|
-
Feb 8th, 2003, 12:22 PM
#1
Thread Starter
New Member
SendInput+DirectX8 App+XP=Not working?
I'm writing an application that needs to send keystrokes to some applications, including a few DirectInput ones.
I'm using the SendInput API, and the code works flawlessly under Windows 2000 - all applications, even the DirectInput ones, are recieving the keystrokes sent.
Unfortunately, the same code, when executed under Windows XP (with the same version of DirectX i have installed in win2000, v8.1) - the keys are picked up by standard applications, such as notepad, but when sent to a DirectInput application (I *think* this only applies when Directinput8 is used, but I'm not certain.), the keystrokes are *not* picked up. Even on the same application that picked them up in Win2000!
Anyone run into this problem before? I've been pulling my hair out over it for weeks now.
A sloppy fix I've found is to drop the Debug DX8 Input DLLS (dinput.dll and dinput8.dll from the DX8.1 SDK) into the apps directory, which then allows it to pick up the keystrokes, but really this isn't a good solution, as some programs have compatibility issues with these DLLs.
Any help on this would be appreciated... it's difficult to explain the context of the project I'm using this for... but sending to these directX applications can't be avoided... and the fact that it works in Win2000 but not in XP is really baffling. Thanks in advance!
Here's the code I'm using currently - there's two subs to trigger the keystrokes, one to press the key down, and one to release the key (this is done so i can keep a key held down for awhile if i need to). I may have missed something in my paste, it's kind of messy at the moment, but I can confirm that this *does* work in Windows 2000... and in XP if it isn't a directinput application recieving the keystrokes.
A good test application is the super nintendo emulator "Zsnes" (http://www.zsnes.com). In XP, the keystrokes will be picked up in the File Browser window, which I can only assume picks up standard keypresses, but when a game is running and you try to send say, whatever key is mapped to 'save state', it is not picked up as I assume at that point the program is monitoring keystate only with directinput. This is just the example I've been testing the code with any rate though, I'm sure many games would behave similarly to this.
In module:
Public Declare Function SendInput Lib "user32.dll" (ByVal nInputs As Long, pInputs As INPUT_TYPE, ByVal cbSize As Long) As Long
Public Declare Sub CopyMemory Lib "kernel32.dll" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Const KEYEVENTF_KEYUP = &H2
Public Type INPUT_TYPE
dwType As Long
xi(0 To 23) As Byte
End Type
Public Const INPUT_KEYBOARD = 1
In form:
Private Sub sendinputtrigger(keynameblah)
Dim inputevents(0 To 3) As INPUT_TYPE ' holds information about each event
Dim keyevent As KEYBDINPUT ' temporarily hold keyboard input info
With keyevent
.wVk = keynameblah ' the key
.wScan = 0 ' not needed
.dwFlags = 0 ' press the key
.time = 0 ' use the default
.dwExtraInfo = 0 ' not needed
End With
inputevents(0).dwType = INPUT_KEYBOARD
CopyMemory inputevents(0).xi(0), keyevent, Len(keyevent)
SendInput 1, inputevents(0), Len(inputevents(0))
End Sub
Private Sub sendinputrelease(keynameblah)
Dim inputevents(0 To 3) As INPUT_TYPE ' holds information about each event
Dim keyevent As KEYBDINPUT ' temporarily hold keyboard input info
With keyevent
.wVk = keynameblah ' the key
.wScan = 0 ' not needed
.dwFlags = KEYEVENTF_KEYUP ' release the key
.time = 0 ' use the default
.dwExtraInfo = 0 ' not needed
End With
inputevents(0).dwType = INPUT_KEYBOARD
CopyMemory inputevents(0).xi(0), keyevent, Len(keyevent)
SendInput 1, inputevents(0), Len(inputevents(0))
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|