I would like to know if someone could please tell me how to simulate a keyboard key press by API.
Thank you in advance.
Printable View
I would like to know if someone could please tell me how to simulate a keyboard key press by API.
Thank you in advance.
You don't neccessarily need an API call - try:
SendKeys "t"
SendKeys "hello world"
SendKeys "{TAB}"
SendKeys "{ENTER}"
SendKeys follows the form:
so if you want to wait for the last key to be pressed before simulating another one, try:Code:SendKeys string [,wait As Boolean]
SendKeys "{DEL}", True
Hope this helps!
thank you very much, but I need the API because i am going to "convert" a joystick button signal to a keyboard key so I will need to use the keyup and keydown. The only possible way to do so is by API
Use the keybd_event API function.
VB Code:
Private Declare Sub keybd_event Lib "user32.dll" (ByVal bVk As _ Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal _ dwExtraInfo As Long) Private Const KEYEVENTF_KEYUP = &H2 Private Sub Command1_Click() Text1.SetFocus keybd_event vbKeyH, 0, 0, 0 keybd_event vbKeyH, 0, KEYEVENTF_KEYUP, 0 keybd_event vbKeyE, 0, 0, 0 keybd_event vbKeyE, 0, KEYEVENTF_KEYUP, 0 keybd_event vbKeyL, 0, 0, 0 keybd_event vbKeyL, 0, KEYEVENTF_KEYUP, 0 keybd_event vbKeyL, 0, 0, 0 keybd_event vbKeyL, 0, KEYEVENTF_KEYUP, 0 keybd_event vbKeyO, 0, 0, 0 keybd_event vbKeyO, 0, KEYEVENTF_KEYUP, 0 End Sub