开发者

Send Key Event to a Child Window

I'm developing an application in python which sends keyboard events to another external application. I use the pywin32 package to set the external application and send the desired key:

import win32com.client as w32
shell = w32.Dispatch("WScript.Shell")

shell.AppActivate(desired_app开发者_如何学编程lication)
shell.SendKeys("{ENTER}")

The external application I'm using has a virtual keyboard and a text area which receives the events of the keyboard. I want to send the key event (in this case, an 'ENTER') to the keyboard area (because the keyboard is making a scan through the letters and will select the desired letter with an Enter). However, my application is sending the key events to the text area instead of the keyboard.

I tried to get the handle of the window I want with FindWindow and EnumChildWindow from win32gui... So, is there a way to send the keys to the specific child window of the external application?


I manage to choose the specific handle with EnumChildWindow (to enumerate all the handles of the application) and send the message with PostMessage.

   import win32api
   win32api.PostMessage(handler, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜