Faking keyboard messages to a C app

pr0fess0r

New member
Joined
Feb 13, 2005
Messages
3
Programming Experience
5-10
Hi
I have a VB.NET app I'm using to send keystrokes to a DOS app (I'm using Quake 2 as an example since I can emss round with the source of that)
I'm using the code below to simulate the keystrokes, and although it works fine for Windows programs like notepad, Quake 2 keeps telling me <unknown_keynum> (0) when i send the keystroke. (Ive told Q2 to output keystrokes it receives to the console). So, it's registering a keyboard event, but doesnt seem to be able to determine what sort of key it is. Here are the relevant code excerpts from the VB app (trying to send the left arrow key):
Private Declare Sub keybd_event Lib "user32" ( _
ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
...
Private Const VK_LEFT As Byte = &H25
Private Const VK_LEFT_MAKE As Byte = &H4B
Private Const VK_LEFT_BREAK As Byte = &HCB
Private Const KEYEVENTF_KEYUP = &H2
...
keybd_event(VK_LEFT, VK_LEFT_MAKE, 0, 0)
keybd_event(VK_LEFT, VK_LEFT_BREAK, KEYEVENTF_KEYUP, 0)

I was told that even though Microsoft claim parameter 2 of keybd_event is unused (the scan code) I should use it, so in this case I just hard-coded the scan codes for the left arrow key, which i got from http://www.codeproject.com/system/keyboard.asp

Can anyone shed any light on where I'm going wrong or what i need to do?
 
Top Bottom