Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deadkeys #42

Closed
SpecialCharacter opened this issue Aug 18, 2017 · 23 comments
Closed

deadkeys #42

SpecialCharacter opened this issue Aug 18, 2017 · 23 comments

Comments

@SpecialCharacter
Copy link

The deadkeys are still not working 100% correctly, I think.

Let's say I want to turn `M into M̀ (a combined character).
But that does not function because there is no character M̀ (at least not in my keyboard layout), so the deadkey remains virtual, until I type a second character (which is ignored in the memory) and the deadkey appears on my screen together with the second character.

I don't know if there is a way to fix this.
What I want to have is the second character not being ignored in the memory.

Also, when I type the deadkey twice, while on my screen the characters are `` (down, down), they are ´` (up, down) in the memory.
I think that is odd...

@logileifs
Copy link

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

@logileifs
Copy link

logileifs commented Aug 18, 2017

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 ?

@moses-palmer
Copy link
Owner

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 è.

@logileifs
Copy link

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?

@SpecialCharacter
Copy link
Author

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

@logileifs
Copy link

@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'))

@SpecialCharacter
Copy link
Author

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?

@logileifs
Copy link

logileifs commented Aug 19, 2017

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)

@SpecialCharacter
Copy link
Author

SpecialCharacter commented Aug 19, 2017

@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?

@logileifs
Copy link

logileifs commented Aug 19, 2017

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

@logileifs
Copy link

@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

@moses-palmer
Copy link
Owner

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

@SpecialCharacter
Copy link
Author

SpecialCharacter commented Aug 23, 2017 via email

@SpecialCharacter
Copy link
Author

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

@moses-palmer
Copy link
Owner

You will have to import KeyCode.

@SpecialCharacter
Copy link
Author

SpecialCharacter commented Aug 24, 2017 via email

@SpecialCharacter
Copy link
Author

SpecialCharacter commented Aug 24, 2017

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?

@SpecialCharacter
Copy link
Author

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?

@SpecialCharacter
Copy link
Author

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

@SpecialCharacter
Copy link
Author

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

@SpecialCharacter
Copy link
Author

SpecialCharacter commented Aug 31, 2017

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)?

@SpecialCharacter
Copy link
Author

SpecialCharacter commented Sep 16, 2017

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?

@moses-palmer
Copy link
Owner

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.

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

No branches or pull requests

3 participants