Giter VIP home page Giter VIP logo

Comments (23)

logileifs avatar logileifs commented on June 22, 2024

Yeah is there any way to detect when user pressed a deadkey to possibly be composing a combined character? We have a lot of those in Icelandic and none seem to work, so far I've tried áíóéýú with no luck

from pynput.

logileifs avatar logileifs commented on June 22, 2024

Okay I just figured out I can use KeyCode.from_dead('`').join(KeyCode.from_char('e')) to combine deadkeys with others and create a combined character but they don't show up right. They show up as grave (è) when they should show up as acute (é). Is there any way around this ?

from pynput.

moses-palmer avatar moses-palmer commented on June 22, 2024

Thank you for your report.

I will look into the issue with disappearing second characters shortly.

@logileifs Did you paste the code correctly? You seem to be joining a grave accent (`) with an e, which should indeed produce è.

from pynput.

logileifs avatar logileifs commented on June 22, 2024

Silly mistake of me, you're absolutely right, I was using the wrong one. One question though, does pynput provide any information on when a dead key is pressed? Or is it just treated as any other alphanumeric character?

from pynput.

SpecialCharacter avatar SpecialCharacter commented on June 22, 2024

Logileifs, can you show me how exactly to use KeyCode.from_dead?
I probably need it in an if ... then structure.

from pynput.

logileifs avatar logileifs commented on June 22, 2024

@SpecialCharacter just exactly like I posted in the comment above. You put your dead key in from_dead and your combining key in from_char. So to produce an è you would do KeyCode.from_dead('`').join(KeyCode.from_char('e'))

from pynput.

SpecialCharacter avatar SpecialCharacter commented on June 22, 2024

The problem is that I need something like

if key.char == 'M':
        elif memory[-2:-1] == '`':
            KeyCode.from_dead('`').join(KeyCode.from_char('M'))

But how do I print it? I suppose with keyboard.type?

from pynput.

logileifs avatar logileifs commented on June 22, 2024

KeyCode.from_dead('`').join(KeyCode.from_char('M')) returns a pynput KeyCode object but you can access its character with .char. So something like this should work:

ḿ = KeyCode.from_dead('`').join(KeyCode.from_char('M'))
print(ḿ.char)

from pynput.

SpecialCharacter avatar SpecialCharacter commented on June 22, 2024

@logileifs it does not work for me :(
As pynput hides the second character after a deadkey from its memory, the triggering event is never released.
Does it work for you?

from pynput.

logileifs avatar logileifs commented on June 22, 2024

well I had not tried it in action yet, only in the interactive interpreter. I just assumed I could catch the deadkeys with something like

if key.char == '´' or key.char == '`':
  dead = key.char
# next key release:
combined_char = KeyCode.from_dead(dead).join(KeyCode.from_char(second_key.char))

I'll try it out and report back how it goes

from pynput.

logileifs avatar logileifs commented on June 22, 2024

@SpecialCharacter I can confirm that it's working for me with the logic above. It's just some pseudo code with the important bits from my code but if you need further clarification I can post some actual samples from my code, just let me know

from pynput.

moses-palmer avatar moses-palmer commented on June 22, 2024

@SpecialCharacter Did the solution provided by @logileifs help you?

from pynput.

SpecialCharacter avatar SpecialCharacter commented on June 22, 2024

from pynput.

SpecialCharacter avatar SpecialCharacter commented on June 22, 2024

Also, now I get a name error:
m̀ = KeyCode.from_dead(dead).join(KeyCode.from_char('m'))
NameError: name 'KeyCode' is not defined

from pynput.

moses-palmer avatar moses-palmer commented on June 22, 2024

You will have to import KeyCode.

from pynput.

SpecialCharacter avatar SpecialCharacter commented on June 22, 2024

from pynput.

SpecialCharacter avatar SpecialCharacter commented on June 22, 2024

Still not working :(
if key.char == '':`

        `dead = key.char`

    `# next key release:`

        `if key == 'm':`

            `m̀ = KeyCode.from_dead(dead).join(KeyCode.from_char('m'))`

            '# dead('`') does not do it either`

            `keyboard.type(m̀.char)`

key ['´'] released [acute]
´
key Key.shift_r released
key '' released ´ [acute, grave]

I type: `m

Why does pynput do the acute when I type the grave?
And the m does not show up?

from pynput.

SpecialCharacter avatar SpecialCharacter commented on June 22, 2024

OK, now the code ALMOST works - if I delete
if key == 'm':
But that means it ALWAYS prints m̀!
How do I get it to respect what character I type after the deadkey?

from pynput.

SpecialCharacter avatar SpecialCharacter commented on June 22, 2024

@logileifs By the way, your m̀ code works!
It just won't let me select the second character… any hint how to do it?

from pynput.

SpecialCharacter avatar SpecialCharacter commented on June 22, 2024

Hi, has somebody come up with a solution how to make the virtual dead key visible to pynput?

from pynput.

SpecialCharacter avatar SpecialCharacter commented on June 22, 2024

Oh, and also Windows splits again ` (grave) into:

key Key.shift_r released
key ['´'] released # (acute)

This behaviour is very annoying. Can you think of a way to fix it?

I mean, there is a difference between m and M, so why not between ` (grave) and ´ (acute)?

from pynput.

SpecialCharacter avatar SpecialCharacter commented on June 22, 2024

Hi again… so has somebody come up with a solution how to make the virtual dead key (not visible to pynput) into a real dead key? It works in Autohotkey, so why not in Python?

from pynput.

moses-palmer avatar moses-palmer commented on June 22, 2024

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)

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.