1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
import win32api, win32con, time, sys
KEYEVENT_KEYDN = 0x0
KEYEVENT_KEYUP = 0x2
VK_SHIFT = 0x10
VK_CTRL = 0x11
VK_ALT = 0x12
VK_UP = 0x26
VK_DOWN = 0x28
VK_TAB = 0x09
VK_OEM_COMMA = 0xBC
VK_OEM_1 = 0xBA
VK_ESCAPE = 0x1B
VK_OEM_PLUS = 0xBB
VK_OEM_MINUS = 0xBD
VK_OEM_PERIOD = 0xBE
VK_SPACE = 0x20
VK_NUMPAD0 = 0x60 # offset numeric keypad 0
def outputtext(text):
for c in text:
outputkey(c)
def outputkey(src, ctrl = False, shift = False, alt = False):
if ctrl: win32api.keybd_event(VK_CTRL, 0, 0, 0)
if alt: win32api.keybd_event(VK_ALT, 0, 0, 0)
if src == ',':
if shift: win32api.keybd_event(VK_SHIFT, 0, 0, 0)
win32api.keybd_event(VK_OEM_COMMA, 0, 0, 0)
win32api.keybd_event(VK_OEM_COMMA, 0, KEYEVENT_KEYUP, 0)
elif src == '+':
shift = True
win32api.keybd_event(VK_SHIFT, 0, 0, 0)
win32api.keybd_event(VK_OEM_PLUS, 0, 0, 0)
win32api.keybd_event(VK_OEM_PLUS, 0, KEYEVENT_KEYUP, 0)
elif src == '=':
win32api.keybd_event(VK_OEM_PLUS, 0, 0, 0)
win32api.keybd_event(VK_OEM_PLUS, 0, KEYEVENT_KEYUP, 0)
elif src == '-':
if shift: win32api.keybd_event(VK_SHIFT, 0, 0, 0)
win32api.keybd_event(VK_OEM_MINUS, 0, 0, 0)
win32api.keybd_event(VK_OEM_MINUS, 0, KEYEVENT_KEYUP, 0)
elif src == '_':
shift = True
if shift: win32api.keybd_event(VK_SHIFT, 0, 0, 0)
win32api.keybd_event(VK_OEM_MINUS, 0, 0, 0)
win32api.keybd_event(VK_OEM_MINUS, 0, KEYEVENT_KEYUP, 0)
elif src == ' ':
if shift: win32api.keybd_event(VK_SHIFT, 0, 0, 0)
win32api.keybd_event(VK_SPACE, 0, 0, 0)
win32api.keybd_event(VK_SPACE, 0, KEYEVENT_KEYUP, 0)
elif src == '.':
if shift: win32api.keybd_event(VK_SHIFT, 0, 0, 0)
win32api.keybd_event(VK_OEM_PERIOD, 0, 0, 0)
win32api.keybd_event(VK_OEM_PERIOD, 0, KEYEVENT_KEYUP, 0)
elif src.isdigit():
chr = VK_NUMPAD0 + int(src)
win32api.keybd_event(chr, chr, 0, 0)
win32api.keybd_event(chr, chr, KEYEVENT_KEYUP, 0)
else:
chr = ord(src.upper())
if src.isupper(): shift = True
if shift: win32api.keybd_event(VK_SHIFT, 0, 0, 0)
win32api.keybd_event(chr, win32api.MapVirtualKey(chr,0), 0, 0)
win32api.keybd_event(chr, win32api.MapVirtualKey(chr,0), KEYEVENT_KEYUP, 0)
if shift: win32api.keybd_event(VK_SHIFT,0, KEYEVENT_KEYUP, 0)
if alt: win32api.keybd_event(VK_ALT,0, KEYEVENT_KEYUP, 0)
if ctrl: win32api.keybd_event(VK_CTRL,0, KEYEVENT_KEYUP, 0)
time.sleep(0.05)
if __name__ == "__main__" :
input = sys.argv[1]
print("input :", input)
outputtext(input) |
Partager