Skip to content

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

Open
ShobanChiddarth wants to merge 8 commits intomoses-palmer:masterfrom
ShobanChiddarth:add-interval-for-type
Open

Added interval functionality for type function of pynput.keyboard.Controller().type#579
ShobanChiddarth wants to merge 8 commits intomoses-palmer:masterfrom
ShobanChiddarth:add-interval-for-type

Conversation

@ShobanChiddarth
Copy link
Copy Markdown

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
Copy Markdown

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
Copy Markdown
Author

👍

@ShobanChiddarth
Copy link
Copy Markdown
Author

Done

@Evidlo
Copy link
Copy Markdown

Evidlo commented Jul 19, 2024

Nice work. Perhaps a test should be added?

@ShobanChiddarth
Copy link
Copy Markdown
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
Copy Markdown

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

@ShobanChiddarth
Copy link
Copy Markdown
Author

ShobanChiddarth commented May 5, 2025

Sorry guys Im too late. I literally forgot I did this PR.

@Evidlo @moses-palmer

@Evidlo
Copy link
Copy Markdown

Evidlo commented May 24, 2025

It's not too late in my opinion.

@ShobanChiddarth
Copy link
Copy Markdown
Author

@Evidlo @moses-palmer what is the status on this PR?

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