Giter Site home page Giter Site logo

Comments (12)

Hyphen-ated avatar Hyphen-ated commented on June 19, 2024

I inserted

print "{} {} {} {}".format(event_type, vk, scan_code, is_extended)

at https://github.com/boppreh/keyboard/blob/master/keyboard/_winkeyboard.py#L368

When I press left alt, this prints
down 164 56 0
up 164 56 0
down 164 56 0
up 164 56 0

When I press right alt, this prints
down 165 56 1
up 165 56 1
down 164 56 0
up 164 56 0

When I press any other key, it only prints two lines.
I'm using a US keyboard.

from keyboard.

Hyphen-ated avatar Hyphen-ated commented on June 19, 2024

The alt key is kind of weird, so maybe it's okay to just say "you know what, you can't bind things directly to the alt key".
But I think it's pretty important for key combos involving alt to work.

def okay():
    print "okay"
keyboard.add_hotkey('alt+q', okay)

This hotkey is triggered once when I press alt+q with the left alt key. It is not triggered when I use the right alt key. In other applications, alt shortcuts work just fine using either alt key.

from keyboard.

Enteleform avatar Enteleform commented on June 19, 2024

OS: Windows 10.0.15063 x64
Python: 3.6.2
Keyboard: Lenovo ThinkPad Compact USB Keyboard

My left-alt key is detected correctly, but the right-alt key is not detected at all.
It is, however, detected by the online key-event-viewer utility that @Hyphen-ated linked to.

All other modifiers work as expected and work on both left & right sides.

Tested with keyboard.hook and keyboard.add_hotkey.

from keyboard.

boppreh avatar boppreh commented on June 19, 2024

I could never reproduce the issue, but detection of alt gr has been greatly improved in the latest version. If anyone who is having this issue could try the master branch, I would greatly appreciate.

from keyboard.

Hyphen-ated avatar Hyphen-ated commented on June 19, 2024

When I run my two test programs from the top of this thread on master, pressing left alt makes them correctly print

alt, 56, down
alt, 56, up

and

down 164 56 0
up 164 56 0

respectively.

Pressing right alt makes them both print nothing.

from keyboard.

boppreh avatar boppreh commented on June 19, 2024

Thank you for the quick answer!

Is your right alt a normal alt key, or an alt gr? Does it work on other applications? Sometimes keys are not mapped at all.

from keyboard.

Hyphen-ated avatar Hyphen-ated commented on June 19, 2024

It's a normal alt key and it works in other applications. It's the same OS and hardware setup as the first two posts in this thread

from keyboard.

boppreh avatar boppreh commented on June 19, 2024

I've looked everywhere and there's only one thing left to test: on _winkeyboard.py there's a check if vk == 165: return True (currently line 493) to skip a duplicated event in case of AltGr. Can you try commenting out that check to see if right alt prints something?

from keyboard.

Hyphen-ated avatar Hyphen-ated commented on June 19, 2024

When I remove that check, I get what looks like it might be correct behavior (I'm not sure about what that 1 at the end instead of 0 for "is_extended" means exactly):

right alt, 56, down
right alt, 56, up

and

down 165 56 1
up 165 56 1

from keyboard.

boppreh avatar boppreh commented on June 19, 2024

I'm revisiting old issues, and I think I found a better (but still not elegant) solution to this problem.

Summary of the problem:

  1. If a keyboard has an alt-gr key, pressing it emits two interleaved events: alt gr and right alt.
  2. If a keyboard only has a right alt key, it only emits a right alt event.

Number 1. is a problem because it makes holding alt gr look like it applies two different modifiers, making a hotkey like alt gr+a not match. The previous hack was to completely discard any events with vk 165 (right alt), because I didn't know any keyboards that had such a key, and at the time it was reporting an incorrect name (menu).

What commit 9a462d2 does is to still discard events with vk 165, but only if they follow an alt gr event. So, still a hack, but closer to the truth. Alt-gr keyboards should report only a single alt-gr event, while right-alt keyboards still pass through.

I need someone to test this solution (available on the master branch) with a keyboard that has a right alt. Until then I'm keeping the issue open, but hopefully solved.

from keyboard.

Hyphen-ated avatar Hyphen-ated commented on June 19, 2024

I checked out master and ran the program from the top of this thread. When I press+release left alt, then right alt, I get this:
alt, 56, down
alt, 56, up
right alt, 56, down
right alt, 56, up

This looks correct

from keyboard.

boppreh avatar boppreh commented on June 19, 2024

Great, thank you. I'm finally closing this issue, but feel free to comment on it again and I'll reopen if you think some problem persists.

from keyboard.

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.