用Python写了一个war3改键,按照自己的习惯改的。。复合hhkb布局

    '''
    Created on 2013-3-25
    @author: Administrator
    '''
    import pythoncom
    import pyHook
    import win32con
    import win32api
    switch = True
    def OnKeyboardEvent(event):
     global switch
     if event.ScanCode == 28: # If hit enter then switch off or on
     switch = not switch
     switchon = event.WindowName == "Warcraft III"
     if switch and switchon:
     if event.Key == 'S': # Map key S as H
     win32api.keybd_event(72, 35, 0, 0)
     win32api.keybd_event(72, 35, win32con.KEYEVENTF_KEYUP, 0)
     return False
     elif event.ScanCode == 1: # Escape == 7
     win32api.keybd_event(103, 71, 0, 0)
     win32api.keybd_event(103, 71, win32con.KEYEVENTF_KEYUP, 0)
     return False
     elif event.ScanCode == 15 and event.Alt == 0: # Tab == 4
     win32api.keybd_event(100, 75, 0, 0)
     win32api.keybd_event(100, 75, win32con.KEYEVENTF_KEYUP, 0)
     return False
     elif event.ScanCode == 57: # Space == 1
     win32api.keybd_event(97, 79, 0, 0)
     win32api.keybd_event(97, 79, win32con.KEYEVENTF_KEYUP, 0)
     return False
     return True

    #def OnMouseEvent(event):
    # global switch;
    # switchon = event.WindowName == "Warcraft III"
    # if switch and switchon:
    # if event.Wheel == 1: #Scroll up == 8
    # win32api.keybd_event(104, 72, 0, 0)
    # return False
    # if event.Wheel == -1: #Scroll down == 2
    # win32api.keybd_event(98, 80, 0, 0)
    # return False
     # if event.Message == 520:
     # win32api.keybd_event(101, 76, 0, 0)
     # return False
    # return True

    hm = pyHook.HookManager()
    hm.KeyDown = OnKeyboardEvent
    #hm.HookMouse()
    hm.HookKeyboard()
    pythoncom.PumpMessages()