0

我试图在 Windows 下实现与在 Linux 环境中实现的相同。串行到键盘输入,请有人帮助或指出正确的方向。我应该尽可能简单,我尝试过但失败了。

import serial
import time
import uinput
import binascii

ser = serial.Serial(
    port='/dev/ttyUSB0',\
    baudrate=115200,\
    parity=serial.PARITY_NONE,\
    stopbits=serial.STOPBITS_ONE,\
    bytesize=serial.EIGHTBITS,\
    timeout=0)

ser.open()

device = uinput.Device([uinput.KEY_A, uinput.KEY_B])

time.sleep(1)
while True:
    datain=ser.read(1)
    if datain=='':
        continue
    datain_int=int(binascii.hexlify(datain), 16)
    datain_bin=bin(datain_int)
    if datain_int==0:
        continue
    if datain_int==128:
        device.emit_click(uinput.KEY_A)
    elif datain_int==64:
        device.emit_click(uinput.KEY_B)
4

1 回答 1

1

我不确定你到底想做什么,但这是我曾经为 GTA San Andreas 构建热键作弊引擎而编写的脚本

import pyHook
import pythoncom
import win32com.client
shell = win32com.client.Dispatch("WScript.Shell")
hm = pyHook.HookManager()
def OnKeyboardEvent(event):
    if event.KeyID == 48:
        #cheat set 1
        shell.SendKeys("chttychttybangbang")
    if event.KeyID == 49:
        #cheat set 2
        shell.SendKeys("hesoyamuzumymwfullclip")
    if event.KeyID == 50:
        #cheat set 3
        shell.SendKeys("hesoyaprofessionalskitfullclip")
    if event.KeyID == 51:
        #cheat set 4
        shell.SendKeys("hesoyalxgiwylfullclip")
    if event.KeyID == 52:
        #cheat set 5
        shell.SendKeys("zeiivgylteiczflyingfisheveryoneisrichspeedfreak")
    if event.KeyID == 53:
        #cheat set 6
        shell.SendKeys("aiwprton")
    if event.KeyID == 54:
        #cheat set 7
        shell.SendKeys("oldspeeddemon")
    if event.KeyID == 55:
        #cheat set 8
        shell.SendKeys("itsallbull")
    if event.KeyID == 56:
        #cheat set 9
        shell.SendKeys("monstermash")
    if event.KeyID == 57:
        #cheat set 10
        shell.SendKeys("jumpjetkgggdkpaiypwzqpohdudeflyingtostunt")
    # return True to pass the event to other handlers
    return True
hm.KeyDown = OnKeyboardEvent
hm.HookKeyboard()
pythoncom.PumpMessages()

它适用于窗户。希望这可以帮助

于 2013-08-07T13:07:34.893 回答