Reputation: 31
So far I have tried pyautogui to send them, but it doesn't work. I was hoping because in the source code it shows this:
'num multiply': '*',
'num divide': '/',
'num add': '+',
'num plus': '+',
'num minus': '-',
'num sub': '-',
'num enter': 'enter',
'num 0': '0',
'num 1': '1',
'num 2': '2',
'num 3': '3',
'num 4': '4',
'num 5': '5',
'num 6': '6',
'num 7': '7',
'num 8': '8',
'num 9': '9',
but that didn't do anything other than what you might expect. It would do regular numbers, and not the numpad specific ones.
pyautogui.press("num 3")
for example, doesn't work at all, and
pyautogui.press("3")
just sends a 3
I have also tried win32api's SendKeys, but that doesn't have the numkeys listed at all, and going through the source code over there, it looks like they're included (https://learn.microsoft.com/en-us/windows/desktop/inputdev/virtual-key-codes) but aren't supported in the Python implementation...so this doesn't work:
>>> import win32api
>>> import win32com.client
>>> shell = win32com.client.Dispatch("WScript.Shell")
>>> shell.SendKeys("{NUMPAD7}")
that returns
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024809), None)
I need to be able to use the numpad keys because I have a setup that uses an emulated mouse that I need to programatically control via those keys. I have figured out a workaround by disabling and re-enabling the emulation (I'm using NeatMouse) via a key-combination that works (and can be sent with SendKeys) because you rarely type and use the mouse at the same time, but I am still very curious about whether what I want to do is actually possible directly.
To reiterate, I want to directly press NUMPAD keys via python.
Thanks!
Upvotes: 2
Views: 14876
Reputation: 45
Based on the official documentation: PyAutoGUI - Keyboard Control Functions it seems that the only problem with your code not working is the space in between "num" and "3". If the documentation is correct you should only change:
pyautogui.press("num 3")
to:
pyautogui.press("num3")
Upvotes: 3