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+.
Press key with pywinauto - Stack Overflow
Another example for pywinauto
how do I use SendKeys? I am using pywinauto 0.6.5 and Python 3.5.1
pywinauto not sending keystrokes to application
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+.
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)
» pip install pywinauto
Hello,
I'm new to using pywinauto for some automation. I'm in the process of making a program that can automate on Pokemon Heartgold by using DesMuME. Initially, I was using pyautogui to automate the keystrokes and it was working perfectly. However, pyautogui needs the window to be in focus, which makes it so that I cannot use my computer to do other things in the meantime. This is when I started looking into pywinauto, to try and send keys to the program in the background while I do other things.
The issue is that none of the keystrokes are being sent. I'm still very new to pywinauto, and I might be doing things incorrectly, but I am not entirely sure. I've tried methods like type_keys(), send_chars() and send_keystrokes() but I was getting errors on each of them. I tried importing the send_keys() method from pywinauto.keyboard, but it doesn't work.
This is the code I have so far to initialize the application:
from pywinauto import Application
from pywinauto.keyboard import send_keys
import pywinauto
import time
app = Application(backend='uia').connect(title_re='DeSmuME')
desmume = app.window(title_re='DeSmuME')
# Even trying to send keystrokes while the window is focused, no luck
# desmume.set_focus()
# attempts at sending keys:
desmume.type_keys('{UP}')
desmume.send_chars('{UP}') # Error
desmume.send_keystrokes('{UP}') # Error
send_keys('{UP}')I don't really know what else there is to try. The pyautogui solution works as it should, but this would make it so much easier to run the program and leave it in the background while I do other things. If anyone knows how to fix, I would greatly appreciate it.