when a key is press ...

Getox

Centurion
Joined
Jul 8, 2004
Messages
122
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?
 
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:

Visual Basic:
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
 
To be honest, im making a trainer for a game :)
so how would i make it say for example "forcefood" when in game?
 
I think using e.Modifiers would be a bit simplier that the Boolean.
Visual Basic:
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
 
DiverDan said:
I think using e.Modifiers would be a bit simplier that the Boolean.
Visual Basic:
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 ;)
 
thenerd said:
As I've said. GetASynchKeyState should get you the State of the Keys at any given time, not sure how to use it. Look it up on google.
i did, and it gave me some crap about cars, google sucks ;)
 
Visual Basic:
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/d...e/keyboardinputfunctions/getasynckeystate.asp
MSDN said:
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
 
Back
Top