Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Press key with pywinauto

Tags:

pywinauto

Extremely straightforward question.

Just want to press a keyboard key. Like enter, using pywin auto. I don't want to press it in the context of any application window.

Just a raw keypress of a keyboard key, like a or enter or backspace.

like image 980
Hangfish Avatar asked Oct 26 '16 14:10

Hangfish


2 Answers

Just use

# from pywinauto.SendKeysCtypes import SendKeys # old for pywinauto==0.5.x
from pywinauto.keyboard import send_keys

send_keys('some text{ENTER 2}some more textt{BACKSPACE}', with_spaces=True)

Docs: https://pywinauto.readthedocs.io/en/latest/code/pywinauto.keyboard.html

P.S. SendKeysCtypes was renamed to keyboard in pywinauto 0.6.0+.

like image 186
Vasily Ryabov Avatar answered Oct 05 '22 11:10

Vasily Ryabov


I had to change the include to get the code working:

from pywinauto.keyboard import send_keys, KeySequenceError

send_keys('some text{ENTER 2}some more textt{BACKSPACE}', with_spaces=True)
like image 31
Olc Avatar answered Oct 05 '22 12:10

Olc