-
Notifications
You must be signed in to change notification settings - Fork 104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Virtual key input is blocked in Windows #4
Comments
The fix for this is to replace the deprecated keybd_event with SendInput as described here: http://stackoverflow.com/a/41057051 I figured this out after looking at http://stackoverflow.com/a/40318692 |
Possibly something like this? ajchili@6f3dadc#diff-3644f6bac665e291284f6df8b749eda1R205 to be honest, I don't know what I'm doing... I tried though!! 👶 |
Update: Input w/ SendInput not working with my current implementation, however I still believe it is what is the issue here. ajchili@5ab03b4 Also, for the past couple hours now I have been trying to get GPUMat to work... keep getting error
|
I tried umat instead of mat for using gpu before, but there was an incompatibility problem. I gonna try it again |
http://stackoverflow.com/questions/35138778/sending-keys-to-a-directx-game By this Q&A, SendMessage function is not moking actual key input, and DirectX app cannot be controled by this function. Keybd_Input can be used for DirectX app but unfortunately it seems like that function is blokced by ETS2 client. We should try other methods like direct input hooking... |
Maybe use postmessage instead of sendmessage? From further reading on stackoverflow, SendInput should definately work. I can check using Spy++ when I get home to confirm this. I'm thinking that using hardware scan codes might work, like they did here: http://stackoverflow.com/a/18854441 |
ajchili@b4ac41f This is my attempt at fixing input. Although I can't check to see if it works because the program outputs "go straight" once and then crashes :( Edit: Also worth noting that we could try
to use hardware scan codes instead of virtual key presses... |
After more testing (ajchili@750a79d), I found that the program freezes after reading line 161 ( |
What does "freeze" mean? Does program stop without crash or something? Maybe that is because of infinite loop without call stack push :( |
Yeah, program freezes because of the issue described here: #6 Freezing means that the program stops working, but doesn't exit or return with an exception. It just hangs and eventually needs to be closed with task manager. I ended up using"-nudge" with Dr. Memory to give me some info on the problem. However I can't get it to display any useful stack trace... In a recent commit (ajchili@6c96498), I edited the code to use hardware scan input, I'm really hoping that works. If I can fix this buffer overflow error, I think we have a good chance of having a working Windows version! Otherwise, we will need to use DirectInput |
Still stuck on the buffer overflow error, but in the meantime I changed the input to follow the original SendMessage format you created. Basically, it goes in the original order that you created. I did change the "0x74" (F5) to "0x44" ('D'), however. I assume that was a typo, since F5 is not really relevant in changing directions. See ajchili@bced2f5?diff=unified#diff-3644f6bac665e291284f6df8b749eda1 |
New Developments! I used Spy++ to see what inputs were being taken by ETS2. Also, I used PE explorer to find out if ETS2 is importing any DirectX dll's. It is NOT using any DirectX dll's, and is instead using Win32 API. Which is great, since it means we will not have to account for DirectInput. This means that keybd_event, SendMessage, and/or PostMessage should work when sending key inputs. Interestingly enough, SendMessage is not in there, only SendMessageW is shown. 'W' stands for Wide or Unicode. Here is the Spy++ log when physically pressing the keys on my keyboard: Real Keys
|
Looking at the Spy++ log, it is evident that we should be using PostMessage to send input. (See the 'P') |
Using PE Explorer, I found out that ETS2 does NOT use any DirectX dll's in it's import tables. It instead uses Win32 API for input (e.g. PostMessageW, SendMessageW, and keybd_event). See bethesirius#4 (comment) Now that we know that ETS2 accepts postmessage, I am removing the SendInput stuff and replacing it with PostMessage. Unfortunately it's not working in-game, but Spy++ verifies that those inputs are being sent to the game window. The simulated keys are identical to the real keys with two exceptions: cRepeat is 0 when simulated, 1 when real, and LPARAM is 0 when simulated, given another value when real. FPS is unfortunately pretty bad, can't deal with this yet until input is working. For now I'm leaving "go straight" to have no messages sent, since it would keep spamming the keydown for A and D, causing lag.
Switched to PostMessage ajchili@e1bc37e Spy++ shows that it is giving nearly identical presses when comparing real and simulated keys. I am not sure why this isn't working. Should probably increase Sleep() time, keys are being pressed far too quickly. Simulated Keys
|
Sorry for my late reply :( . |
No problem! You may want to make the SendInput an array. I've tried using both Scan codes and Virtual keys but it's still not working for me. Frustrating! I'm still not sure if the KEYEVENTF_SCANCODE flag is actually defined... For example:
I think we will need to use SendInput because PostMessage does not alter LPARAM as far as I know. Also, using SendInput makes my program crash. PostMessage has great FPS. |
Input works now: ajchili@b8746df Thanks to Komat for suggesting to change the di8.keyboard/fusion.mouse in the controls.sii to sys.keyboard/sys.mouse. Edit: I mean it works in that ETS2 is receiving the input and moving the truck. However, it is sending keys too fast, and adding Sleep() makes the program crash... So for now it's not working "correctly" Edit2: Now with sys.mouse, we can change SendInput to use mouse instead, which would mimic input in linux branch. Edit3: ajchili@efcd613 zeromemory is kind of redundant so getting rid of that. |
We now know to use SetCursorPos to control the mouse. I think this issue can be closed now? |
OK. Input in windows is now working. Thanks! |
So I know this thread is three years old, though it helped me better understand I was trying to figure out the purpose of the scan code argument since I found putting 0 instead of the actual scan code of the key worked for applications like notepad and games like 7 days to die which seem to use DirectX. I came upon this thread and decided to try out the method on Euro Truck Simulator 2 and it lead to some interesting discoveries. To keep it short:
So, so far it seems to get the best results from I don't mean no downside to keybd_event, since an argument can be made due to its deprecation and documentation suggests using SendInput. Though in python at least, SendInput isn't in win32api but in a different package called ctypes Note: I have only tested this on one system, so unsure if get different results using different systems. |
We used WM_KEYINPUT function and keybd_event funtion to drive the truck automatically, but thevirtual key input with those functions is blocked. Specifically, virtual key input is working on other programs, such as notepad or ms word, but we could not handle the truck with virtual key input.
The text was updated successfully, but these errors were encountered: