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
  How to get first two characters in a string scratchmyhead 2 371 May-19-2020, 11:00 AM
Last Post: scratchmyhead
  Remove escape characters / Unicode characters from string DreamingInsanity 5 952 May-15-2020, 01:37 PM
Last Post: snippsat
  Python Consecutive characters vijju56 4 487 Apr-22-2020, 11:03 AM
Last Post: TomToad
  Win32API Troubles daaaabs 2 470 Mar-24-2020, 08:19 PM
Last Post: daaaabs
  Replacing characters in a string with a list cjms981 1 502 Dec-30-2019, 10:50 PM
Last Post: micseydel
  Strange Characters in JSON returned string fioranosnake 4 922 Dec-02-2019, 07:25 PM
Last Post: fioranosnake
  Split a long string into other strings with no delimiters/characters krewlaz 4 551 Nov-15-2019, 02:48 PM
Last Post: ichabod801
  input string split Eric7Giants 3 759 Nov-13-2019, 07:19 PM
Last Post: Gribouillis
  with input remove a string from the list konsular 3 592 Oct-12-2019, 09:25 AM
Last Post: konsular
  simple string & input problem kungshamji 5 843 Jun-23-2019, 03:54 PM
Last Post: kungshamji

Forum Jump:

User Panel Messages

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