moses-palmer / pynput

Sends virtual input commands
GNU Lesser General Public License v3.0
1.78k stars 247 forks source link

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

Open Bata94 opened 10 months ago

Bata94 commented 10 months ago

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: