Skip to content
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

How to press 2(or more) keys then release them respectively ? #105

Open
j7168908jx opened this issue Feb 11, 2018 · 1 comment
Open

How to press 2(or more) keys then release them respectively ? #105

j7168908jx opened this issue Feb 11, 2018 · 1 comment

Comments

@j7168908jx
Copy link

I was using PyUserInput on windows and was trying to simulate different kind of input.
(py27, win64)

I tried something like this:

import ...    
k = pykeyboard.PyKeyboard()
k.press_key('a')
k.press_key('b')
time.sleep(2)
k.release_key('a') # line a
k.release_key('b') # line b

And I want it to help me play games like 'osu!' or something similar.
In this game, it requires player to do the key pressing and releasing with the rythm of music, and one of the rythm pattern looks like above.

However, I found that this script cannot perform line a or b as I expected, which is something like pressing key 'a' and 'b' at the same time, and after exactly 2 seconds, I release both of them.
As indicated from the game, I knew that one of the key 'a' and key 'b' was never released, until the next time I used k.press_key('a') .

How may I fix the problem ? I have tried something like this:

import ...
a = pykeyboard.PyKeyboard()
b = pykeyboard.PyKeyboard()
a.press_key('a')
b.press_key('b')
time.sleep(2)
a.release_key('a')
b.release_key('b')

and it's not working.

By the way, I encountered the long press problem, as PyKeyboard cannot simulate something like one was pressing the really keyboard in a text field, which would display like 'aaaaaaaaaaaaaaaaaa'. Though It seemingly had no infulence on my game, as the game thought I was pressing the key, I guess there may be something influencing both of my questions.

Thanks!

@j7168908jx
Copy link
Author

I tried the same in C++, where I use

keybd_event(val,0,0,0);
keybd_event(val,0,KEYEVENTF_KEYUP,0);

to do the pressing and releasing, which worked well in my case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant