Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

how would i do this:

 

if ctrl+1 is pressed how would i make it output text?

 

like if i had notepad open and i pressed ctrl+1 it would output hello

 

how would i do this?

Page Edit 2.0 Alpha 2 OUT NOW!

- Download Now -

Posted

You want this to work as a universal hotkey?

 

If so, I think GetASynchKeyState api would work for you.

 

Otherwise, if you just want it to work in your program, you use the form's keydown event and keyup events. You set booleans for control and 1 and if both booleans are true, control 1 is being pressed:

 

dim control as boolean
dim one as boolean
private sub form1_keydown()
if e.keycode = keys.control then
control = true
elseif e.keycode = keys.1 then
one = true
end if
if control and one then
messagebox.show("CONTROL + 1")
end if
end sub

private sub form1_keyup()
if e.keycode = keys.control then
control = false
elseif e.keycode = keys.1 then
one = false
end if
end sub

  • *Experts*
Posted

I think using e.Modifiers would be a bit simplier that the Boolean.

Public Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.D1 And e.Modifiers = Keys.Control Then
TextBox1.Text = "forcefood"
End If
End Sub

Member, in good standing, of the elite fraternity of mentally challenged programmers.

 

Dolphins Software

Posted
I think using e.Modifiers would be a bit simplier that the Boolean.

Public Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
If e.KeyCode = Keys.D1 And e.Modifiers = Keys.Control Then
TextBox1.Text = "forcefood"
End If
End Sub

Would i need "GetASynchKeyState" for it to work or?

 

Basicly i want to open a game press ctrl+1 and it will activate the cheat ;)

Page Edit 2.0 Alpha 2 OUT NOW!

- Download Now -

Posted
As I've said. GetASynchKeyState should get you the State of the Keys at any given time' date=' not sure how to use it. Look it up on google.[/quote']

i did, and it gave me some crap about cars, google sucks ;)

Page Edit 2.0 Alpha 2 OUT NOW!

- Download Now -

  • Leaders
Posted

Private Declare Function GetAsyncKeyState Lib "user32.dll" (ByVal vKey As Int32) As Short

It is pretty simple to use. Try experimenting. I figured out how to use it by throwing it into VB6 and whipping up a quick test app.

 

GetAsyncKeyState returned a negative value for the following keycodes when control and F1 are being held down: 17 (control), 162 (left control), 163 (right control), and 112 (F1).

 

i did, and it gave me some crap about cars, google sucks

Here is a crazy idea: search MSDN.

 

From http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/keyboardinput/keyboardinputreference/keyboardinputfunctions/getasynckeystate.asp

Parameters

 

vKey

[in] Specifies one of 256 possible virtual-key codes. For more information, see Virtual-Key Codes.

 

Windows NT/2000/XP: You can use left- and right-distinguishing constants to specify certain keys. See the Remarks section for further information.

 

Return Value

 

If the function succeeds, the return value specifies whether the key was pressed since the last call to GetAsyncKeyState, and whether the key is currently up or down. If the most significant bit is set, the key is down, and if the least significant bit is set, the key was pressed after the previous call to GetAsyncKeyState[/Quote]

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...