Giter VIP home page Giter VIP logo

Comments (10)

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

A degree sign is not a combining character.

When creating dead keys using pynput.keyboard.KeyCode, pynput assumes that you pass the non-combining character for a dead key, such as '~' for COMBINING TILDE U+0303. To work around this, do the following:

from pynput.keyboard import KeyCode

dead = KeyCode(char='°')
dead.is_dead = True
dead.combining = u'\u0325'

print(dead.join(KeyCode.from_char('L')))

from pynput.

SpecialCharacter avatar SpecialCharacter commented on July 20, 2024

from pynput.

SpecialCharacter avatar SpecialCharacter commented on July 20, 2024

from pynput.

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

So the crash happens in pynput without the callback ever reaching you code?

Does the following snippet cause the crash?

from pynput import keyboard
with keyboard.Listener() as listener:
    listener.join()

I don't have a degree sign on my keyboard, so I cannot test.

from pynput.

SpecialCharacter avatar SpecialCharacter commented on July 20, 2024

from pynput.

SpecialCharacter avatar SpecialCharacter commented on July 20, 2024

Actually, it crashes every time I type ° (degree), even if it is the first thing I do.

Does your degree key work?

from pynput.

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

Unfortunately my keyboard does not have a degree sign, so I cannot really test it.

But if the crash happens inside pynput without even reaching your code, it is definitely a bug in the library.

It happens because Windows, when calling MapVirtualKeyEx, sets the most significant bit, indicating that the character is a diacritic, or a dead character.

pynput works under the assumption that MapVirtualKeyEx(MAPVK_VK_TO_CHAR, ...) will return a pre-composed combining character in these cases, so that pressing for example the dead key marked ~ will return TILDE. This does not appear to be the case. Is the degree sign an actual dead key on your keyboard? It seems reasonable to assume that it would then return RING ABOVE instead of DEGREE SIGN.

from pynput.

SpecialCharacter avatar SpecialCharacter commented on July 20, 2024

from pynput.

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

@SpecialCharacter, does this still happen with the master branch with a corrected keyboard listener?

from pynput.

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

This is a duplicate of #199, which has more recent activity, so I will close this issue.

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.