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?
#1
Hi,

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:

    win32gui.SetForegroundWindow(hld)
    win32api.keybd_event(0x46, 0, ) # F
Reply
#2
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:
print(hld)
# or better format
print(f"You typed: {hld}")
Reply
#3
Hi

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
Reply
#4
https://stackoverflow.com/questions/6441...characters
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using string input for boolean tronic72 3 634 Nov-01-2023, 07:48 AM
Last Post: Gribouillis
  doing string split with 2 or more split characters Skaperen 22 2,317 Aug-13-2023, 01:57 AM
Last Post: Skaperen
Sad How to split a String from Text Input into 40 char chunks? lastyle 7 1,054 Aug-01-2023, 09:36 AM
Last Post: Pedroski55
  How do I check if the first X characters of a string are numbers? FirstBornAlbratross 6 1,426 Apr-12-2023, 10:39 AM
Last Post: jefsummers
Big Grin General programming question (input string)[ jamie_01 2 1,568 Jan-08-2022, 12:59 AM
Last Post: BashBedlam
Question [SOLVED] Delete specific characters from string lines EnfantNicolas 4 2,141 Oct-21-2021, 11:28 AM
Last Post: EnfantNicolas
  Creating new column with a input string drunkenneo 2 2,194 Apr-14-2021, 08:10 AM
Last Post: drunkenneo
  Extract continuous numeric characters from a string in Python Robotguy 2 2,579 Jan-16-2021, 12:44 AM
Last Post: snippsat
  How to get first two characters in a string scratchmyhead 2 2,031 May-19-2020, 11:00 AM
Last Post: scratchmyhead
  Remove escape characters / Unicode characters from string DreamingInsanity 5 13,410 May-15-2020, 01:37 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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