Giter VIP home page Giter VIP logo

Comments (7)

moses-palmer avatar moses-palmer commented on July 20, 2024

I have pushed a fix to the master branch.

Instead of always using XSendEvent, which is necessary to handle multiple layouts, pynput no uses XFAKE for control keys.

Please notify if this fixes your issue---it worked for my local tests.

from pynput.

kenjitoyama avatar kenjitoyama commented on July 20, 2024

Thanks for the quick fix, Moses. Now Key.ctrl, Key.shift, Key.alt and Key.cmd send non-synthetic keys. I can use Key.cmd for example to trigger the application menu.

However, Key.tab still sends a synthetic key, which still doesn't trigger application switching:

KeyRelease event, serial 38, synthetic YES, window 0x4e00001,
root 0x498, subw 0x0, time 0, (0,0), root:(0,0),
state 0x0, keycode 23 (keysym 0xff09, Tab), same_screen NO,
XLookupString gives 1 bytes: (09) " "
XFilterEvent returns: False

Side question: What happens if all keys, including normal letter keys, are sent as non-synthetic?

from pynput.

moses-palmer avatar moses-palmer commented on July 20, 2024

I quickly checked the documentation for (XSendEvent)[https://tronche.com/gui/x/xlib/event-handling/XSendEvent.html] and XKeyEvent, and it does not seem to support manipulating the synthetic flag. PyUserInput uses XFAKE, which is a server extension, for sending fake events; I presume this is why it can set the flag.

Normal letters cannot be sent through XFAKE if a general solution compatible with the pynput API guarantees is sought; XFAKE does not support sending keys not mapped in the layout, and maintains its own modifier mapping.

I have pushed a new set of commits; now all keys with a known virtual key code are sent through XFAKE, thus allowing control keys and modifiers to be non-synthetic. I extended my local tests with alt+tab, and that too works now.

from pynput.

kenjitoyama avatar kenjitoyama commented on July 20, 2024

Hey, you're very quick! It works beautifully now. =) Thanks very much!

from pynput.

kenjitoyama avatar kenjitoyama commented on July 20, 2024

Hmm, something has changed though. Example:

Python 2.7.12 (default, Jul 1 2016, 15:12:24)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.

from pynput.keyboard import Key, Controller

keyboard = Controller()
keyboard.press('a')
Traceback (most recent call last):
File "", line 1, in
File "build/bdist.linux-x86_64/egg/pynput/keyboard/_base.py", line 371, in press
File "build/bdist.linux-x86_64/egg/pynput/keyboard/_xorg.py", line 204, in _handle
File "/usr/lib/python2.7/contextlib.py", line 24, in exit
self.gen.next()
File "build/bdist.linux-x86_64/egg/pynput/_util/xorg.py", line 76, in display_manager
pynput._util.xorg.X11Error: [(BadValue(), None)]

I installed pynput just now from 024dfd7

from pynput.

moses-palmer avatar moses-palmer commented on July 20, 2024

I had a feeling this would be one of those ;-)

I made the mistake of not running the test suite after the modifications; it was so small, right?

I have pushed yet another set of commits that changes the default value of pynput.KeyCode.vk to None, which is a saner value, and what the previous patch expected.

Thank you for your input and testing!

from pynput.

kenjitoyama avatar kenjitoyama commented on July 20, 2024

Thanks again, Moses. Your new commits fixed the issues. From what I could tell, everything works perfectly now. Maybe you'll want to close this issue to keep your issue tracker clean again.

Thanks for the great work!

from pynput.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.