Anonymous avatar Anonymous committed e191196

adding script to test sending a character to a window

Comments (0)

Files changed (1)

3171045/test-window.py

+import win32ui
+import win32con
+import time
+from ctypes import *
+
+PUL = POINTER(c_ulong)
+class KeyBdInput(Structure):
+	_fields_ = [("wVk", c_ushort),
+				("wScan", c_ushort),
+				("dwFlags", c_ulong),
+				("time", c_ulong),
+				("dwExtraInfo", PUL)]
+
+class HardwareInput(Structure):
+	_fields_ = [("uMsg", c_ulong),
+				("wParamL", c_short),
+				("wParamH", c_ushort)]
+
+class MouseInput(Structure):
+	_fields_ = [("dx", c_long),
+				("dy", c_long),
+				("mouseData", c_ulong),
+				("dwFlags", c_ulong),
+				("time",c_ulong),
+				("dwExtraInfo", PUL)]
+
+class Input_I(Union):
+	_fields_ = [("ki", KeyBdInput),
+				 ("mi", MouseInput),
+				 ("hi", HardwareInput)]
+
+class Input(Structure):
+	_fields_ = [("type", c_ulong),
+				("ii", Input_I)]
+
+def send_char(char):
+	FInputs = Input * 1
+	extra = c_ulong(0)
+	ii_ = Input_I()
+	KEYEVENTF_UNICODE = 0x4
+	ii_.ki = KeyBdInput( 0, ord(char), KEYEVENTF_UNICODE, 0, pointer(extra) )
+	x = FInputs( ( 1, ii_ ) )
+	windll.user32.SendInput(1, pointer(x), sizeof(x[0]))
+
+if __name__ == '__main__':
+	wnd = win32ui.FindWindow(None, '* Untitled - Notepad2 (Administrator)')
+	type_this = 'jaraco'
+	wnd.SetFocus()
+	wnd.SetForegroundWindow()
+	for char in type_this:
+		send_char(char)
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.