Python Forum

Full Version: Python win32api keybd_event: How do I input a string of characters?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

I used the below to get the Window Handle of an app and bring it to be the focus. I want to type in a string of characters into the app. But using win32api.keybd_event, I am able to type in only single characters? Is there a way to type in a string of characters?

Eg, "I am happy"

Thank you
import win32gui
import win32api
import win32con

hld = win32gui.FindWindow (None, "UNTITLED") # Returns the handle of the window titled UNTITLED

if hld>0:

    win32api.keybd_event(0x46, 0, ) # F
I don't believe there has been a build for python 3, and as such, would render win32gui obsolete.
If all you need to do is input a string of characters, you can use:
hld = input("Please enter a string of characters: ")
# to show results:
# or better format
print(f"You typed: {hld}")

Thanks for the reply. But I don't think u understand my query. I want to input a string of characters into an app. Not ask users to provide an input.

If key.event can't do then. How about SendInput function?

Thank you