Skip to content

Instantly share code, notes, and snippets.

@silmang
silmang / textonthescreen.py
Created April 29, 2016 11:04
[python] text on the windows screen
import win32api, win32con, win32gui, win32ui
def main():
hInstance = win32api.GetModuleHandle()
className = 'MyWindowClassName'
# https://msdn.microsoft.com/en-us/library/windows/desktop/ms633576(v=vs.85).aspx
# win32gui does not support WNDCLASSEX.
wndClass = win32gui.WNDCLASS()
# https://msdn.microsoft.com/en-us/library/windows/desktop/ff729176(v=vs.85).aspx
@silmang
silmang / receivekeys.py
Last active April 27, 2016 07:59
[python] receive key events
from collections import namedtuple
KeyboardEvent = namedtuple('KeyboardEvent', ['event_type', 'key_code', 'scan_code', 'alt_pressed', 'time'])
handlers = []
def listen():
from ctypes import windll, CFUNCTYPE, POINTER, c_int, c_void_p, byref
import win32con, win32api, win32gui, atexit
@silmang
silmang / sendkey.py
Last active November 1, 2020 09:23
[python] windows send key and mouse code
import ctypes, time
SendInput = ctypes.windll.user32.SendInput
# C struct redefinitions
PUL = ctypes.POINTER(ctypes.c_ulong)
class KeyBdInput(ctypes.Structure):
_fields_ = [("wVk", ctypes.c_ushort),
("wScan", ctypes.c_ushort),
("dwFlags", ctypes.c_ulong),
@silmang
silmang / clipboard.py
Created April 27, 2016 07:20
[python] get windows clipboard text data
import ctypes
def winGetClipboard():
ctypes.windll.user32.OpenClipboard(0)
pcontents = ctypes.windll.user32.GetClipboardData(13) # CF_UNICODETEXT
data = ctypes.c_wchar_p(pcontents).value
ctypes.windll.user32.CloseClipboard()
return data
print (winGetClipboard())