|
-
Jan 14th, 2011, 01:40 AM
#1
Thread Starter
New Member
[Resolved] Simulating keystokes and focus issues (virtual game pad for tablet UPC)
Edit: I finally found something that works! Hooking the mouse, preventing actual mouse clicks when the mouse is over the control form and calling the click events manually did the trick 
I've recently been working on a virtual game pad to be controlled by a mouse (or more likely a touch screen on a tablet UPC). It is nearing completion and works exactly as I had hoped except for one issue. I created a topic about it in the VB6 section though as of yet I havn't found a working solution. jemidiah suggested I consider porting it to .NET if anyone here can give some insight.
 Originally Posted by Me, other topic
I'm using the keybd_event API to simulate keystrokes on the target application. It does the job rather well, except for the fact that keybd_event requires focus on the target in order for it to work, and with the application I've used for testing (Project64 1.6) and assumedly other applications, the keys that are simulated are lost every time the target application loses focus, which happens quite a lot, in fact every time the virtual pad is clicked to press another button.
This isn't an issue in most cases, however if a virtual button has been set to hold down (by clicking on it and dragging away), clicking anything else will make that key get released, at least until it resends all of the ones that are supposed to be held down. Even then it isn't always an issue, but for example if I'm using it to play Mario Kart and I want to hold down a banana behind me, as soon as I try to steer or anything else it will be let go.
Failed solutions:
Using postmessage (doesn't require focus) rather than keybd_event
- Sends keystrokes to file menu rather than game, sending to child hwnds doesn't work either
Bringing target window to foreground (using setforegroundwindow or setwindowpos) during the WM_ACTIVATE event
- Still loses keystates as when it is brought to foreground during a click event and prevents click events on the form from activating (so buttons don't work either)
Disabling mouse clicks on the form by using SetCapture Me.hwnd during the Form_MouseMove
- Prevents form from getting focus however does not prevent target window from losing focus
Possible solutions:
Hooking the target window and setting back to foreground during the event where focus is lost eg WM_KILLFOCUS
- Tried by calling this c++ .dll and this one but I was unable to catch this event or even the WM_ACTIVATE event for some reason, though some other events were working and the events I needed were showing up in spy++ for the same window
Hooking the target and canceling the WM_KILLFOCUS
- Same issue for hooking target as previous solution
Disabling mouse clicks altogether somehow while still being able to capture the mouse state (possible redirect to another key?) to program custom click events
- Yet to find code that disables mouse clicks but still allows mouse to move, etc. Tried useing SetWindowsHookEx with WH_MOUSE_LL and could catch events, though I have no idea how to cancel the damn things...
So, does somebody have an idea?
Original topic
Source code
Last edited by xXSnowyXx; Jan 18th, 2011 at 10:40 AM.
Tags for this Thread
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
|