The code can be re-written simpler:

import pywinauto

app = pywinauto.application.Application().connect(title_re='Form1')
Form1 = app.Window_(title_re='Form1', class_name='WindowsForms10.Window.8.app.0.2bf8098_r13_ad1')
Form1.SetFocus()
Form1.TypeKeys("{PAUSE 2}")
Form1.TypeKeys("{TAB 2}{PAUSE 2}{ENTER}")

TypeKeys automatically sets a focus to the Form1 and types the keys. SendKeys doesn't set a focus because it's not aware about the window. That's probably why it doesn't work with SendKeys.

[EDIT] Of course you need to run the script as Administrator.

Answer from Vasily Ryabov on Stack Overflow
🌐
Stack Overflow
stackoverflow.com › questions › 50656751 › pywinauto-send-key-down-to-application
python - pywinauto send key down to application - Stack Overflow
from pywinauto.keyboard import SendKeys <...code> SendKeys('{DOWN}') # Keyboard input # in case of element element.type_keys('{DOWN}') ... Sign up to request clarification or add additional context in comments. ... When I say "key down" I mean holding keys down, not down arrow. Also, does this send it the application or just replicate keyboard events in the active window?
🌐
Readthedocs
pywinauto.readthedocs.io › en › latest › code › pywinauto.keyboard.html
pywinauto.keyboard — pywinauto 0.6.8 documentation
Automate typing keys or individual key actions (viz. press and hold, release) to an active window by calling send_keys method.
Discussions

Send keystrokes not work for notepad and other programs
Windows GUI Automation with Python (based on text properties) - pywinauto/pywinauto More on github.com
🌐 github.com
3
April 7, 2022
pywinauto not sending keystrokes to application
Make sure you've set DeSmeME to receive input even when it's not focused. I took a quick look through some of the source code and found this line: https://github.com/TASEmulators/desmume/blob/master/desmume/src/frontend/windows/main.cpp#L564 const bool willAcceptInput = ( allowBackgroundInput || (mainWindow == GetForegroundWindow()) ); Which tells me that there's an option somewhere to allow it to process input when the window is not in focus. If it is enabled, then I'm not sure what the problem is. I don't have experience with pywinauto. Fun fact I noticed: Some of the code in DeSmuME is taken from snes9x lol. More on reddit.com
🌐 r/learnpython
4
2
May 19, 2024
winforms - How to send SendKeys to Windows form in python script? - Stack Overflow
I'm doing automation scripting in Python for my desktop application. In that I'm sending TAB key/any key to my windows form. But I'm not able to find handle of that Windows form in my Python script. ... __author__ = 'juhis' import SendKeys import sys import os from Tkinter import * import ctypes import win32gui import pywinauto ... More on stackoverflow.com
🌐 stackoverflow.com
July 11, 2018
Press key with pywinauto - Stack Overflow
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. ... Save this answer. Show activity on this post. ... # from pywinauto.SendKeysCtypes import SendKeys # old for pywinauto==0.5.x from pywinauto.keyboard import ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GitHub
github.com › pywinauto › pywinauto › issues › 533
how do I use SendKeys? I am using pywinauto 0.6.5 and Python 3.5.1 · Issue #533 · pywinauto/pywinauto
August 7, 2018 - I am trying to send the following ####to a terminal window### from pywinauto import keyboard keyboard.SendKeys.send('jsmith') ######################## but when I try to run the above, I rec...
Author   volksmania
🌐
Python Forum
python-forum.io › thread-17735.html
[PyWinAuto] Please help me with Typekeys ()
Hello everyone, I have some code as below: from pywinauto import application from pywinauto import keyboard app = application.Application() app.connect(path= r'C:\Windows\system32\cmd.exe') dlg = app.top_window_() dlg.TypeKeys('cd /d C:\Program Files...
🌐
GitHub
github.com › pywinauto › pywinauto › issues › 1202
pywinauto/pywinauto
April 7, 2022 - application connect to a notepad · send_keystrokes · from pywinauto.application import Application app = Application().connect(title_re="a.txt") app.top_window().send_keystrokes("aaaaa") Pywinauto version: 0.6.8 · Python version and bitness: 3.7 · Platform and OS: windows 10 ·
Author   gitE0Z9
🌐
Reddit
reddit.com › r/learnpython › pywinauto not sending keystrokes to application
r/learnpython on Reddit: pywinauto not sending keystrokes to application
May 19, 2024 -

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.

Find elsewhere
🌐
Readthedocs
airelil-pywinauto.readthedocs.io › en › latest › code › pywinauto.keyboard.html
pywinauto.keyboard — pywinauto 0.6.6 documentation
Keyboard input emulation module · Automate typing keys or individual key actions (viz. press and hold, release) to an active window by calling send_keys method
🌐
Readthedocs
pywinauto.readthedocs.io › en › uia › code › pywinauto.keyboard.html
pywinauto.keyboard — pywinauto 0.6.0.rc1 documentation
Check that SendInput can work the way we want it to · The tips and tricks at http://www.pinvoke.net/default.aspx/user32.sendinput might be useful! exception pywinauto.keyboard.KeySequenceError¶ · Exception raised when a key sequence string has a syntax error · pywinauto.keyboard.SendKeys(keys, pause=0.05, with_spaces=False, with_tabs=False, with_newlines=False, turn_off_numlock=True)¶ ·
🌐
YouTube
youtube.com › rafique javed
Desktop GUI Automation using Keyboard Controls || Python PywinAuto || Simplest way to Automate - YouTube
This video describes about automating a GUI application using Keyboard Controls.Link for Keycodes,https://pywinauto.readthedocs.io/en/latest/code/pywinauto.k...
Published   August 6, 2020
Views   4K
🌐
GitHub
github.com › pywinauto › pywinauto › issues › 133
SendKeys/TypeKeys always sends text to active window, ignores target · Issue #133 · pywinauto/pywinauto
January 19, 2016 - Using Windows 7, Anaconda Python 3.5 (32bit). pxplus[u'Edit4'].TypeKeys('9.26') Simply sends the text 9.26 directly to my text editor instead of the control specified. I've tried this with other controls also without success. Unfortunate...
Author   ghost
Top answer
1 of 2
2

For the specified UI element this method is

# it will activate target window if it's not in focus
ditto.ditto.SysListView321.type_keys('^e')

but

keyboard.SendKeys('^e') # should work also if you don't change active window

It can be used without binding to any specific control.

So you shouldn't try using module name (like keyboard) as an attribute name of any object. It's Python. Just learn Python basics and you will understand pywinauto better as well.

2 of 2
1

To complete Vasily's answer. Here is the code needed to edit a single ditto item (it works... most of the time)

from pywinauto import findbestmatch
from pywinauto.application import Application
from pywinauto import remote_memory_block
from pywinauto import keyboard
from pywinauto import timings
import time  #needed for time.sleep(3)


keyboard.SendKeys('^*') # custom shortcut to launch the specific ditto "group" 
time.sleep(2)  # wait 2 sec for the app

ditto=Application().connect(path='Ditto.exe')
time.sleep(0.5) 

##find & select item

#The list of texts to search through: 
texts = ditto.ditto.SysListView321.texts()[1:] #skip window text itself

# The list of items corresponding (1 to 1) to the list of texts to search through.
items = ditto.ditto.SysListView321.items()   #>>[]  

found_item = findbestmatch.find_best_match('test', texts, items, limit_ratio=0.1).Select()

## Extra: open the item in editor
# Bring the window to the foreground first
ditto.ditto.set_keyboard_focus() # (work also with set_focus but it remove the cursor) 

# edit the selected entry (it's a shortcut)
keyboard.SendKeys('^e') 

# Wait (for the windows to load)
time.sleep(1) # 1 sec

# Select all
keyboard.SendKeys('^a')

ditto.Editor.close()
🌐
Reddit
reddit.com › r/python › another example for pywinauto
r/Python on Reddit: Another example for pywinauto
September 12, 2018 - # Another pywinauto example from pywinauto import Desktop, Application, keyboard import time # Open Calculator in Windows 10 and do some calculation app = Application(backend='uia').start("calc.exe") dlg = Desktop(backend="uia").Calculator dlg.type_keys('3') # Add some delay between each key stroke time.sleep(1) dlg.type_keys('/') time.sleep(1) dlg.type_keys('7') time.sleep(1) dlg.type_keys('=') # Get calculation result txt = dlg.Static3.texts() # Get only the numeric value txt = txt[0].split(' ')[2] # Open Notepad from Windows 10 app2 = Application(backend='uia').start("notepad.exe") time.sle
🌐
GitHub
github.com › pywinauto › pywinauto › issues › 1111
Sendkeystrokes and Mouseclick on minimized window · Issue #1111 · pywinauto/pywinauto
September 11, 2021 - from pywinauto.application import Application target_window = win32gui.FindWindow(None, (args["windowtitle"])) app = Application() app.connect (handle=target_window) app.window(title=args["windowtitle"]).send_keystrokes("{VK_ESCAPE}") app.window(title=args["windowtitle"]).click(button='left', coords=(1191,1044))
Author   madtatu-development
🌐
Read the Docs
app.readthedocs.org › projects › airelil-pywinauto › downloads › pdf › latest pdf
pywinauto Documentation Release 0.6.6 The pywinauto contributors community
July 28, 2006 - pywinauto is a set of python modules to automate the Microsoft Windows GUI. At it’s simplest it allows you to send · mouse and keyboard actions to windows dialogs and controls. ... The core concept is described in the Getting Started Guide. A lot is done through attribute access (__getattribute__) for each class. For example when you get the attribute · of an Application or Dialog object it looks for a dialog or control (respectively).
🌐
Radiosky
radiosky.com › rjp3 › rjp3help › sendkeys_reference.html
SendKeys Reference
Note You can't use SendKeys to send keystrokes to an application that is not designed to run in Microsoft Windows.
🌐
Readthedocs
pywinauto-fork.readthedocs.io › en › latest › code › pywinauto.keyboard.html
pywinauto.keyboard — pywinauto 0.6.5 documentation
Keyboard input emulation module · Automate typing keys or individual key actions (viz. press and hold, release) to an active window by calling send_keys method