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

Keyboardtracking CTRL + "second_key" doesn't output "second_key" #578

Open
Bata94 opened this issue Dec 7, 2023 · 0 comments
Open

Keyboardtracking CTRL + "second_key" doesn't output "second_key" #578

Bata94 opened this issue Dec 7, 2023 · 0 comments

Comments

@Bata94
Copy link

Bata94 commented Dec 7, 2023

Not sure if it is really an issue, but I wasn't able to find something useful about this...
I am trying to track the Keyboard Inputs, of a User if they press a combination with any CTRL-Key.

The regular tracking works fine. But as soon as I press CTRL + any regular Key, the output is unusable for me, because it changes the expected Key Output completely...

In the example I am pressing & releasing "a" first, then CTRL_L, then CTRL_L + "a".

So does someone know how I can "translate" the "\x01" output to "CTRL + a" or something like that? :D

Logging Output:

>> 08:58:46.694 | v1.0.0 | DEBUG -> Line 413: 'a' pressed -> <class 'pynput.keyboard._win32.KeyCode'>
>> 08:58:46.695 | v1.0.0 | DEBUG -> Line 415: Type: KeyCode
>> 08:58:46.695 | v1.0.0 | DEBUG -> Line 417: char: a
>> 08:58:46.695 | v1.0.0 | DEBUG -> Line 425: ['a']
>> 08:58:46.696 | v1.0.0 | DEBUG -> Line 433: 'a' released
>> 08:58:47.697 | v1.0.0 | DEBUG -> Line 413: Key.ctrl_l pressed -> <enum 'Key'>
>> 08:58:47.697 | v1.0.0 | DEBUG -> Line 425: [<Key.ctrl_l: <162>>]
>> 08:58:47.798 | v1.0.0 | DEBUG -> Line 433: Key.ctrl_l released
>> 08:58:50.541 | v1.0.0 | DEBUG -> Line 413: Key.ctrl_l pressed -> <enum 'Key'>
>> 08:58:50.541 | v1.0.0 | DEBUG -> Line 425: [<Key.ctrl_l: <162>>]
>> 08:58:51.140 | v1.0.0 | DEBUG -> Line 413: '\x01' pressed -> <class 'pynput.keyboard._win32.KeyCode'>
>> 08:58:51.143 | v1.0.0 | DEBUG -> Line 415: Type: KeyCode
>> 08:58:51.143 | v1.0.0 | DEBUG -> Line 417: char: ☺
>> 08:58:51.144 | v1.0.0 | DEBUG -> Line 425: [<Key.ctrl_l: <162>>, '\x01']
>> 08:58:51.144 | v1.0.0 | DEBUG -> Line 433: '\x01' released
>> 08:58:51.354 | v1.0.0 | DEBUG -> Line 433: Key.ctrl_l released

Callback Functions:

def keyboard_on_press(self, key):
    try:
        logger.debug(f"{key} pressed -> {type(key)}")
        if type(key) is keyboard._win32.KeyCode:
            logger.debug("Type: KeyCode")
            if key.char:
                logger.debug(f"char: {key.char}")
            elif key.is_dead:
                logger.debug(f"is_dead: {key.is_dead}")
            elif key.vk:
                logger.debug(f"vk: {key.vk}")
            
        if key not in self.pressedKeys:
            self.pressedKeys.append(key)
            logger.debug(self.pressedKeys)
            
        if keyboard.Key.ctrl in self.pressedKeys:
            logger.debug(f"ctrl + {key} pressed")
    except e as Exception:
        logger.warn(e)

def keyboard_on_release(self, key):
    logger.debug(f"{key} released")
    if key in self.pressedKeys:
        self.pressedKeys.remove(key)
    else:
        logger.warn(f"{key} not found in List!!")

Used Versions:

  • Windows 11 Pro (tried Windows 10 as well)
  • Python 3.11.4
  • Pynput 1.7.6
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

1 participant