Python Forum
Python win32api keybd_event: How do I input a string of characters?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python win32api keybd_event: How do I input a string of characters?

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

Possibly Related Threads…
Thread Author Replies Views Last Post
Question [SOLVED] Delete specific characters from string lines EnfantNicolas 4 387 Oct-21-2021, 11:28 AM
Last Post: EnfantNicolas
  Creating new column with a input string drunkenneo 2 794 Apr-14-2021, 08:10 AM
Last Post: drunkenneo
  Extract continuous numeric characters from a string in Python Robotguy 2 896 Jan-16-2021, 12:44 AM
Last Post: snippsat
  How to get first two characters in a string scratchmyhead 2 912 May-19-2020, 11:00 AM
Last Post: scratchmyhead
  Remove escape characters / Unicode characters from string DreamingInsanity 5 4,854 May-15-2020, 01:37 PM
Last Post: snippsat
  Python Consecutive characters vijju56 4 2,500 Apr-22-2020, 11:03 AM
Last Post: TomToad
  Win32API Troubles daaaabs 2 1,585 Mar-24-2020, 08:19 PM
Last Post: daaaabs
  Replacing characters in a string with a list cjms981 1 948 Dec-30-2019, 10:50 PM
Last Post: micseydel
  Strange Characters in JSON returned string fioranosnake 4 2,514 Dec-02-2019, 07:25 PM
Last Post: fioranosnake
  Split a long string into other strings with no delimiters/characters krewlaz 4 1,258 Nov-15-2019, 02:48 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020