Comments (21)
Getting the 2nd issue (enter key problems) on my setup as well:
Windows 10
Python 2.7.10
pynput 1.2
from pynput.
Thank you for your report and condensed sample code.
Unfortunately, I cannot reproduce the error. My setup is slightly different though:
- Windows 10, running in VirtualBox.
- No background utilities modifying keyboard events running.
1: I'm using a utility called "Steelseries Engine 3" version 3.9.6 to bind some of my mouse buttons to alt-left, alt-right, and ctrl-w. With pynput active in the background, about half of the time I press one of these buttons, the modifier key gets lost. So I sometimes get the letter "w" sent by itself instead of the ctrl-w shortcut combination. (tested in Chrome and notepad++)
Do you mean that only the virtual keypresses generated by Steelseries Engine 3 are dropped? Can you reproduce this without that utility running?
@Brett824: Do you also use a similar tool?
from pynput.
Do you mean that only the virtual keypresses generated by Steelseries Engine 3 are dropped? Can you reproduce this without that utility running?
I've been unable to trigger the problem by physically pressing ctrl-w, but the dropped Enter presses I described are from physical presses of the Enter key. I can reproduce the Enter problem without the Steelseries utility running.
These issues are more inconsistent than I described yesterday. When testing it again today, they're happening much less: it takes a minute or so of reproduction attempts before I start briefly seeing either problem, then it goes away again.
from pynput.
I will continue testing to try to reproduce.
I think that the current system load might be a factor; pynput is registered as a keyboard hook, and during its execution, the keyboard event is not propagated further; a system under load could possibly cause a pause in the python process, which possibly could cause the event to be dropped.
Do you notice any difference when testing on a newly started system, and when testing under heavy load?
from pynput.
Today both variations of the problem are back to being instantly reproducible, with a lower CPU load than I had during my tests yesterday. So that suggests there's more to it than load. My guess is there's a race condition happening inside the windows keyboard input subsystem
from pynput.
A probably-related discovery: while playing the game Refunct ( http://store.steampowered.com/app/406150/ ) with the example program running in the background, physical presses of the Esc key are dropped about 98% of the time. (pressed Esc a few hundred times to test it.) The peak rate I ever got for the other problems was something like 50-60%.
While this game was running I tried launching a bunch of other CPU intensive things and seeing how reliably the ctrl-w problem would manifest, and I couldn't get it to happen at all in about 100 tries. So it looks unlikely to me that the problem is based on CPU load.
from pynput.
I'm sorry, but I just cannot reproduce this.
I have tried several hundred keypresses, focussing on enter and escape, with HD video playing in the background, and not a single one has been lost. Are you absolutely certain that you can reproduce it without any of the input modifying tools you have installed running?
from pynput.
Yes, I am am absolutely certain.
I went and found a free game made on the same engine as Refunct (unreal engine 4) on the theory that any UE4 game will show the problem reliably. The first one I tried does give me the problem: https://bohrium.itch.io/age-of-snowmpires
I can click "start game", pick the top option, and then try to press esc to bring up a menu. It fails about 80-90% of the time for me when pynput is running.
from pynput.
Thank you for the link.
Unfortunately the game does not work under VirtualBox, which I use to run Windows. I am going to have to ask you to help me troubleshoot.
Monitoring events enter pynput here on Windows and will eventually end up here.
The data passed to the handler is however not suitable to pass on to consumers of pynput, as only platform dependent key codes are passed. To convert these codes to usable data, KeyTranslator.__call__
is used. I suspect this is the culprit. What happens if you avoid calling self._translator
in self._translate
and just return a dummy value?
If that stops the problem from appearing, we are on to something. Possible causes of the error in that case are calls to ToUnicodeEx, which is called here, here and here.
from pynput.
I replaced the call to self._translator with "return {}" and all the problems I was having appeared to go away.
from pynput.
Did you investigate further? Does the issue still occur if you comment out only parts of KeyTranslator.__call__
? What if you replace line 460 with modified_char = None
?
from pynput.
Sorry, I don't have enough interest to put that much more into this. I'm just going to switch to keyboard I think
from pynput.
def new_translate(self, vk, is_press):
""" Fix for moses-palmer/pynput/issues/15 """
return {
"vk": vk
}
keyboardListener._translate = new_translate
I did this myself and it allowed everything to work fine, since for my use case I only needed the VK anyway.
(I'm very interested in this issue and I am experiencing the same problem as this)
Replacing line 460 with modified_char = None
yields no effect.
from pynput.
I will add similar functionality shortly. The translation routine cannot be changed like this, obviously, since then a lot of useful information is lost, but I will add a filter function to be invoked on the raw data with the ability to suppress normal handling. Your use case would then be covered.
from pynput.
from pynput.
from pynput.
Sorry for the long delay, but I have been rather busy.
I have pushed a new feature branch that, while not solving the root cause, will help with your issues.
It allows passing an additional argument to listeners, win32_event_filter
, which will be called before other system hooks are called and before the event is propagated further in the listener. It will be passed the arguments (msg, data)
, where msg
is the current low-level message being handled, and data
is associated data. You will find more information in the documentation, bu in short, you can return None
to stop pynput from handling the event further and is similar to your new_translate
function above.
from pynput.
One thing you could to to help track down the issue would be to add debug prints to the code and perhaps wrap all of of SystemHook._handler in a try-catch block to verify that it is not caused by something silly like an unhandled exception.
from pynput.
A similar problem is with Autoit3.
With listeners ON, Send("^c",0) sends just character C rather than Ctrl+C.
Any work-arounds?
from pynput.
In response to this issue, win32_event_filter
was added. It allows you to intercept keyboard events before they are transformed by pynput; make sure to return False
from your callback.
It does bring the limitation that you will have to write a special event callback just for Windows, and you get raw keyboard events rather than platform agnostic Key
instances.
from pynput.
I have created issue #49 as a container for all win32 keyboard listener related issues, as I suspect that the root cause is the same.
I will close this issue. If you think the problem is unrelated to #49, please reopen this issue.
from pynput.
Related Issues (20)
- Which python version is the latest release of pynput compatible with?
- Keyboardtracking CTRL + "second_key" doesn't output "second_key"
- pynput not detecting media keys on kde plasma wayland HOT 1
- Type method crashes on cyrillic characters HOT 1
- Suppress mouse move not working when using parsec HOT 1
- mouse listener example for win32_event_filter HOT 1
- Script Continues Rapid Clicking Despite Mouse Button Release (is_pressed Functionality Issue) HOT 6
- Press cmd_r and release with cmd pressed will produce two presses instead of press + release HOT 3
- Can this be used in Micropython? HOT 5
- Get the original pressed key HOT 1
- The Numpad numbers does not work in HotKeys.
- pynput types ">" instead of "|" HOT 1
- Need to sync keyboard lock keys
- AttributeError: record_create_context HOT 5
- capslock crshed on macOS HOT 2
- lazy imports cause a KeyError HOT 4
- Cannot install on linux Ubuntu (depends on pywin32) HOT 2
- name 'keyboard' is not defined HOT 1
- Additional keys can still trigger events HOT 2
- Missing 1.7.7 tarball on PyPI
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pynput.