moses-palmer / pynput

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

Numpad Return None #370

Open Toolknight opened 3 years ago

Toolknight commented 3 years ago

Hey Guys, i have a problem, every digit from my Numpad returns None. i found on this: if hasattr(key, 'vk') and 96 <= key.vk <= 105: print('You entered a number from the numpad: ', key.char) but it still return None.

You know how to fix this? Already a lot of thanks to you guys

moses-palmer commented 3 years ago

Thank you for your report.

When you say that your numpad returns None, do you mean that key.char is printed as None? That is expected, as there is no character representation for those characters. Do you still get different values for key.vk?

pieterhelsen commented 2 years ago

Hi, I have this same issue. I'm not sure why this is expected. Shouldn't key.char return '5' when pressing '5' on the numpad?

image

pieterhelsen commented 2 years ago

I've currently solved this by mapping key.vk to the numeric representation on an application level, but I still maintain that this would better be handled on the level of pynput.

inputs = {
    96: "0",
    97: "1",
    98: "2",
    99: "3",
    100: "4",
    101: "5",
    102: "6",
    103: "7",
    104: "8",
    105: "9",
}

if hasattr(key, 'vk') and 96 <= key.vk <= 105:
    logger.debug(f'The keypad was pressed: {inputs[key.vk]}')
    key_buffer += inputs[key.vk]