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

Added interval functionality for type function of pynput.keyboard.Controller().type #579

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

ShobanChiddarth
Copy link

Each press and release can be delayed interval seconds if the required delay time is provided in the argument when calling the function.

Now each key press+release will have `interval` amount of time in between them
of `pynput.keyboard.Controller().type()`
@XaverKlemenschits
Copy link

This would be a useful feature.
I would even suggest to add another parameter to control for how long the button is pressed, as this was a problem I encountered with some not-very-responsive web interfaces. Then users can choose the length of the key press and the time between two separate key strokes.

See https://github.com/Evidlo/passhole/pull/64/files#diff-b60a6055af04b5a093f4c39c708a87d60e3b0f54d14552548e18af445966425fR590-R598 for details on how I proposed to solve this.

@ShobanChiddarth
Copy link
Author

👍

@ShobanChiddarth
Copy link
Author

Done

@Evidlo
Copy link

Evidlo commented Jul 19, 2024

Nice work. Perhaps a test should be added?

@ShobanChiddarth
Copy link
Author

@Evidlo

Nice work. Perhaps a test should be added?

I really don't know how to do that. I have never used tests in my life.

@Evidlo
Copy link

Evidlo commented Jul 30, 2024

https://github.com/moses-palmer/pynput/blob/master/tests/keyboard_controller_tests.py#L91-L94

Basically just modify the test to call type(..., hold=XXX, interval=YYY). This will just test that the arguments work without error, not that the actual delays are working correctly. That may be good enough.

If you want to run the tests:

$ pip install -e .
$ python -m unittest tests/keyboard_controller_tests.py

+================================================+
| This test case is non-interactive, so you must |
| not use the keyboard.                          |
|                                                |
| You must, however, keep this window focused.   |
+------------------------------------------------+
.a
.... 
.AaA
.A
.... 
.ã
.~
.~
.abc123, "quoted!"
.Hello	world
.Hello World
.Teclado (informática)
Компьютерная клавиатура
.
----------------------------------------------------------------------
Ran 19 tests in 4.869s

OK

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

Successfully merging this pull request may close these issues.

3 participants