示例#1
0
def main():
    PrevMAP = None
    subprocess.Popen(["CandyCrush.exe"])
    u_input = raw_input("Start? (y/n)\n")
    if u_input == 'y' or u_input == 'Y':
        print("Go")
    else:
        exit(1)
    while(1):
        #u_input = raw_input("next move? (y/n)\n")
        #print(u_input)
        time.sleep(2)
        win32api.keybd_event(win32con.VK_F2, 0, 0, 0)
        time.sleep(2)
        Cor,MAP,row,col = read_map()
        if np.array_equal(PrevMAP ,MAP):
            continue
        else:
            PrevMAP = MAP
        if PrevMAP==None:
            PrevMAP = MAP
        
        print(row,col)
        leagal_move = search(MAP,row,col)
        Pos,x,y,direction = Make_move(leagal_move,row,col,MAP)
        print(Pos,x,y,direction)
        if direction==1:
            click(Cor[Pos][0],Cor[Pos][1],Cor[Pos+1][0],Cor[Pos+1][1])
        elif direction==2:
            click(Cor[Pos][0],Cor[Pos][1],Cor[Pos-1][0],Cor[Pos-1][1])
        elif direction==3:
            click(Cor[Pos][0],Cor[Pos][1],Cor[Pos-col][0],Cor[Pos-col][1])
        elif direction==4:
            click(Cor[Pos][0],Cor[Pos][1],Cor[Pos+col][0],Cor[Pos+col][1])
示例#2
0
def t3():
    mouse_click(1024, 470)
    str = 'hello'
    for c in str:
        win32api.keybd_event(VK_CODE[c], 0, 0, 0)  # a键位码是86
        win32api.keybd_event(VK_CODE[c], 0, win32con.KEYEVENTF_KEYUP, 0)
        time.sleep(0.01)
示例#3
0
def SendToRConsole(aString):
    global RConsole
    SendToVimCom("\x09Set R as busy [SendToRConsole()]")
    finalString = aString.decode("latin-1") + "\n"
    win32clipboard.OpenClipboard(0)
    win32clipboard.EmptyClipboard()
    win32clipboard.SetClipboardText(finalString)
    win32clipboard.CloseClipboard()
    if RConsole == 0:
        FindRConsole()
    if RConsole:
        win32api.keybd_event(0x11, 0, 0, 0)
        try:
            win32api.PostMessage(RConsole, 0x100, 0x56, 0x002F0001)
        except:
            vim.command("call RWarningMsg('R Console window not found [1].')")
            RConsole = 0
            pass
        if RConsole:
            time.sleep(0.05)
            try:
                win32api.PostMessage(RConsole, 0x101, 0x56, 0xC02F0001)
            except:
                vim.command("call RWarningMsg('R Console window not found [2].')")
                pass
        win32api.keybd_event(0x11, 0, 2, 0)
示例#4
0
文件: QWOP.py 项目: dhillonsh/QWOP
def clickKey(key):
    while(True):
        sleepTime = uniform(0,1)
        print("Pressing " + key + " for " + str(sleepTime) + " seconds")
        win32api.keybd_event(moveList[key], 0, 0,0)
        sleep(sleepTime)
        win32api.keybd_event(moveList[key],0 ,win32con.KEYEVENTF_KEYUP,0)
示例#5
0
def jump():
	win32api.keybd_event(win32con.VK_SPACE,
						 0,
						 win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
	time.sleep(0.1)
	keyEvent = win32con.KEYEVENTF_EXTENDEDKEY | win32con.KEYEVENTF_KEYUP
	win32api.keybd_event(win32con.VK_SPACE, 0, keyEvent, 0)
示例#6
0
 def push_button(self, button):
     #print(button)
     if button in self.macros.keys(): #convert macro to something else
         button=self.macros[button]
         if '+' in button:
             buttons=button.split("+") #this enables macros to loophole the one command limit
             for x in buttons:
                 self.push_button(x)#yay minor recursion
             return
     if button in self.keymap.keys():
         win32api.keybd_event(self.button_to_key(button), 0, 0, 0)
         time.sleep(.15)
         win32api.keybd_event(self.button_to_key(button), 0, win32con.KEYEVENTF_KEYUP, 0)
     elif button.lower()=='mup': #I could have done this better but too lazy to fix now
         self.mup()
     elif button.lower()=='mdown':
         self.mdown()
     elif button.lower()=='mleft':
         self.mleft()
     elif button.lower()=='mright':
         self.mright()
     elif button.lower()=='wait':
         time.sleep(3)
     elif button.lower().startswith('r'):
         self.clickR(button[1:])
     elif button.lower().startswith('l'):
         self.clickL(button[1:]) 
     elif button.lower().startswith('m'):
         self.clickM(button[1:])
     elif button.lower().startswith('w'):
         self.clickW(button[1:])    
示例#7
0
def key_press(key):
    # TODO: Make this non-blocking
    win32api.keybd_event(key, 0, 0, 0)
    # reactor.callLater(.02, win32api.keybd_event,key, 0,
    #                   win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(.02)
    win32api.keybd_event(key, 0, win32con.KEYEVENTF_KEYUP, 0)
示例#8
0
def pressKey(myKey):
    win32api.keybd_event(
        myKey, 0x45, win32con.KEYEVENTF_EXTENDEDKEY | 0, 0)
    win32api.keybd_event(
        myKey, 0x45,
        win32con.KEYEVENTF_EXTENDEDKEY | win32con.KEYEVENTF_KEYUP, 0)
    print 'Send key event done.'
示例#9
0
 def keyEventMap(self,keytype):
     
     keymap = { '21' : 175,          #VolumeUp
                '22' : 174,          #VolumeDown
                '23' : 173,          #VolumeMute
                '27' : 27,           #ESCAPE
                '32' : 32,           #SPACE
                '37' : 37,           #left Arrow
                '38' : 40,           #UP Arrow
                '39' : 39,           #Right Arrow
                '40' : 38,           #Down Arrow
                '45' : 116,          #F5
                '65' : 65,           #game   Left
                '68' : 68,           #game   Right
                '73' : 73,           #game   A
                '74' : 74,           #game   B
                '75' : 75,           #game   X
                '77' : 77,           #game   LB
                '78' : 78,           #game   RB
                '83' : 83,           #game   Down
                '85' : 85,           #game   Y
                '87' : 87            #game   Up
                 }
     key = keymap.get(keytype)
     if key == None:
         return None
     win32api.keybd_event(key,0,0,0)
     win32api.Sleep(45)
     win32api.keybd_event(key,0,win32con.KEYEVENTF_KEYUP,0)
示例#10
0
 def test_topic6(self):
     driver = self.driver
     driver.get(self.base_url)
     sleep(0.1)
     driver.refresh()
     win32api.keybd_event(34,0,0,0)
     sleep(1)    
     now_handle = driver.current_window_handle
     ele = driver.find_element_by_xpath(".//*[@id='activity-list']/div[3]/a/img")
     ActionChains(driver).move_to_element(ele).click().perform() 
     all_handles =driver.window_handles
     for handle in all_handles:
         if handle != now_handle:
             driver.switch_to.window(handle)
             judge = driver.find_element_by_xpath(".//*[@id='footer']/div[2]/div/div[1]/div[1]/div[3]/h3").text
             self.assertEqual(judge,u"关于我们",msg="this page is incorrect")
             new_handle = driver.current_window_handle        
             driver.find_element_by_xpath("html/body/div[2]/div/div[7]/div/a").click()#春风十里
             sleep(1)
             new_all_handle = driver.window_handles
             for handlenew in new_all_handle:
                 if handlenew != new_handle and handlenew != now_handle:
                     driver.switch_to.window(handlenew)
                     url = driver.current_url
                     statusCode =urllib.urlopen(url).getcode()
                     self.assertEqual(statusCode,200,msg="page status error")
                     title = driver.find_element_by_xpath("html/body/div[2]/div/div[3]/div[2]/div[1]/span[2]/span[4]").text
                     self.assertEqual(title,u"提车日记",msg="this car is invisible")
示例#11
0
def pushButtons( bestBoard ):
    if bestBoard == 0: ##near top / collision
        return
##    print 'sleep 1 s'
##    time.sleep(2)
    SLEEP = .05
    nummoves = bestBoard.numRotate + bestBoard.numLeft + bestBoard.numRight
    for a in range( bestBoard.numRotate):
        print 'rotate'
        ##rotate
        win32api.keybd_event( 0x26, 0 ) #up
        time.sleep(SLEEP)
    for a in range( bestBoard.numLeft):
        print 'left'
        ##left
        win32api.keybd_event( 0x25, 0 ) #left
        time.sleep(SLEEP)
    for a in range( bestBoard.numRight):
        print 'right'
        ##right
        win32api.keybd_event( 0x27, 0 ) #right
        time.sleep(SLEEP)

    if nummoves > 0:
        for a in range(3): #push it down
            print 'down'
            win32api.keybd_event(0x28, 0,0,0)
            time.sleep(SLEEP)
            win32api.keybd_event(0x28,0,2,0)
            time.sleep(SLEEP)
示例#12
0
 def genEvent(self,action,updown):
     
     if action.find('None') == 0:
         pass
     elif action.find('mouse') == -1:
         if updown=='down':
             win32api.keybd_event(VK_CODE[action],0,)
         elif updown=='up':
             win32api.keybd_event(VK_CODE[action],0,2)
     elif action.find('Left') != -1:
         x,y = self.GetPosition()
         if updown=='down':
             win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x, y)
         elif updown=='up':
             win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x, y)
     elif action.find('Right') != -1:
         x,y = self.GetPosition()
         if updown=='down':
             win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN,x, y)
         elif updown=='up':
             win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP,x, y)
     elif action.find('Middle') != -1:
         x,y = self.GetPosition()
         if updown=='down':
             win32api.mouse_event(win32con.MOUSEEVENTF_MIDDLEDOWN,x, y)
         elif updown=='up':
             win32api.mouse_event(win32con.MOUSEEVENTF_MIDDLEUP,x, y) 
def key():
    interval = 0.3
    while True:
        time.sleep(interval )

        win32api.keybd_event(65,0,0,0) #a键位码是86
        win32api.keybd_event(65,0,win32con.KEYEVENTF_KEYUP,0)
示例#14
0
def winEnumHandler( hwnd, ctx ):
    if win32gui.IsWindow( hwnd ) and win32gui.IsWindowVisible( hwnd ) and win32gui.IsWindowEnabled( hwnd ):
        print 'HEX', hex(hwnd), 'Text:', win32gui.GetWindowText( hwnd )
        if 'Administrator' in win32gui.GetWindowText( hwnd ):
            print 'try to setfore'
#            win32gui.SetActiveWindow(hwnd)
#            win32gui.BringWindowToTop(hwnd)
#            win32gui.SetFocus(hwnd)
#            win32gui.SetForegroundWindow(hwnd)
#            win32gui.ShowWindow(hwnd,win32con.SW_SHOWDEFAULT)

            
#            win32api.PostMessage(hwnd, win32con.WM_KEYDOWN, win32con.VK_F1, 0)
#            win32api.PostMess2age(hwnd, win32con.WM_KEYUP, win32con.VK_F1, 0)
#            win32api.PostMessage(hwnd, win32con.WM_SETTEXT, None, 'win32con.VK_F1')
#            win32api.PostMessage(hwnd, win32con.WM_KEYDOWN, win32con.VK_TAB, 0)
#            win32api.keybd_event(86,0,0,0)221
#            win32api.keybd_event(86,0,win32con.KEYEVENTF_KEYUP,0)
#            SendMessage(hwnd, 258, ord('a'), 0)
#            win32api.keybd_event(112,0,0,0)2
#            win32api.keybd_event(112,0,win32con.KEYEVENTF_KEYUP,0)
#            win32api.SendMessage(hwnd, win32con.WM_KEYDOWN, win32con.VK_RETURN, 0)
#            time.sleep(1)
#            win32api.SendMessage(hwnd, win32con.WM_KEYUP, win32con.VK_RETURN, 0)
#            win32api.keybd_event(127,0,0,0)
#            win32api.keybd_event(86,0,0,0)  
#            win32api.keybd_event(86,0,win32con.KEYEVENTF_KEYUP,0) 
#            win32api.keybd_event(17,0,win32con.KEYEVE2NTF_KEYUP,0)
            win32api.keybd_event(50,0,0,0)  
示例#15
0
def pressKey(key = 'A', times = 10000, delay = 0, downTime = 0.1, reclickTime = 0.1):
    time.sleep(delay)
    for i in range(times):
        win32api.keybd_event(ord(key), 0, win32con.KEYEVENTF_EXTENDEDKEY, 0)
        time.sleep(downTime)
        win32api.keybd_event(ord(key), 0, win32con.KEYEVENTF_KEYUP, 0)
        time.sleep(reclickTime)
示例#16
0
 def fake_key(self, keycode, press):
     kc = self.keycodes.get(keycode)
     if kc is None:
         log.warn("no keycode found for %s", keycode)
         return
     #see: http://msdn.microsoft.com/en-us/library/windows/desktop/ms646304(v=vs.85).aspx
     win32api.keybd_event(win32con.SHIFT_PRESSED, 0, win32con.KEYEVENTF_EXTENDEDKEY, 0)
示例#17
0
def keyCombo(pauseSecound,*arg):
    for key in arg:
        win32api.keybd_event(key,0,0,0)
    for key in arg:
        win32api.keybd_event(key,0,win32con.KEYEVENTF_KEYUP,0)
    if pauseSecound > 0:
        time.sleep(pauseSecound)
示例#18
0
def release(*args):
    """
    release depressed keys
    accepts as many arguments as you want.
    e.g. release('left_arrow', 'a','b').
    """
    for i in args:
        win32api.keybd_event(VK_CODE[i], 0, win32con.KEYEVENTF_KEYUP, 0)
示例#19
0
    def _hold(self, key):
        if key is not None:
            win32api.keybd_event(key, 0, win32con.KEYEVENTF_EXTENDEDKEY, 0)

        yield

        if key is not None:
            win32api.keybd_event(key, 0, win32con.KEYEVENTF_KEYUP, 0)
示例#20
0
 def cancelMode(self):
     # ending exclusive mode if in it, also ending the mode it is in
     winkey = win32con.VK_LWIN         # 91
     keyup = win32con.KEYEVENTF_KEYUP  # 2
     if self.winkeyDown:
         print 'tasks, cancelMode, release WINKEY'
         win32api.keybd_event(winkey, 0, keyup, 0)  # key up
         self.winkeyDown = 0
示例#21
0
文件: main.py 项目: jtara1/tol-bot
 def returnToLobby(self):
     win32api.keybd_event(0x1B,0,0,0)
     win32api.keybd_event(0x1B,0,win32con.KEYEVENTF_KEYUP,0)
     time.sleep(1)
     self.moveMouse(Coords.lobby_button)
     self.clickLMB()
     time.sleep(15) # seconds required to load to lobby
     print 'Logged out to lobby'
示例#22
0
 def _worker(self):
     while self._running:
         for entry in self._job_queue.get():
             time.sleep(entry.delay)
             if entry.isup:
                 win32api.keybd_event(entry.keycode, 0, win32con.KEYEVENTF_KEYUP, 0)
             else:
                 win32api.keybd_event(entry.keycode, 0, 0, 0)
示例#23
0
文件: win32_.py 项目: LoveShun/tools
def keybd_down():
    """按下方向键“下”
    """
    import win32api
    import win32con
    win32api.keybd_event(40, 0, 0, 0)
    win32api.keybd_event(40, 0, win32con.KEYEVENTF_KEYUP, 0)
    return None
示例#24
0
 def led_on(self, keys):
     nVirtKey = {
         "caps lock": win32con.VK_CAPITAL,
         "num lock": win32con.VK_NUMLOCK,
     }[keys]
     if(not win32api.GetKeyState(nVirtKey)):
         win32api.keybd_event(nVirtKey, 0, 0, 0)
         win32api.keybd_event(nVirtKey, 0, win32con.KEYEVENTF_KEYUP, 0)
示例#25
0
文件: Keyboard.py 项目: kmittmann/Bot
 def pressAndHold(self, *args):
     '''
     press and hold. Do NOT release.
     accepts as many arguments as you want.
     e.g. pressAndHold('left_arrow', 'a','b').
     '''
     for i in args:
         win32api.keybd_event(self.VK_CODE[i], 0,0,0)
示例#26
0
def unstickCapsLock():
    import win32api
    import win32con

    # Simulate a key up
    win32api.keybd_event( win32con.VK_CAPITAL, 0x45, win32con.KEYEVENTF_EXTENDEDKEY | win32con.KEYEVENTF_KEYUP, 0 );
    # simulate a key down
    win32api.keybd_event( win32con.VK_CAPITAL, 0x45, win32con.KEYEVENTF_EXTENDEDKEY, 0 );       
def presskey(x):
    shell = win32com.client.Dispatch('WScript.Shell')
    shell.AppActivate('bgb')
    time.sleep(0.1)
    print 'press '+str(x)
    win32api.keybd_event(VK_CODE[x],0,0,0)
    time.sleep(0.3)
    win32api.keybd_event(VK_CODE[x],0,win32con.KEYEVENTF_KEYUP,0)
示例#28
0
文件: main.py 项目: jtara1/tol-bot
 def exitGame(self):
     # 0x12 = alt (hex Virtual key code), 0xb8 = alt (bScanCode)
     # 0x74 = f4
     win32api.keybd_event(0x1B,0,0,0)
     win32api.keybd_event(0x1B,0,win32con.KEYEVENTF_KEYUP,0)
     self.moveMouse(Coords.exit_button)
     self.clickLMB()
     print 'Game exited'
示例#29
0
文件: print.py 项目: OuSatoru/Teller
def pressAndHold(*args):
    #'''
    #press and hold. Do NOT release.
    #accepts as many arguments as you want.
    #e.g. pressAndHold('left_arrow', 'a','b').
    #'''
    for i in args:
        win32api.keybd_event(VK_CODE[i], 0, 0, 0)
        time.sleep(SLEEP_TIME)
示例#30
0
def press(*args):
    """
    one press, one release.
    accepts as many arguments as you want. e.g. press('left_arrow', 'a','b').
    """
    for i in args:
        win32api.keybd_event(VK_CODE[i], 0, 0, 0)
        time.sleep(.05)
        win32api.keybd_event(VK_CODE[i], 0, win32con.KEYEVENTF_KEYUP, 0)
示例#31
0
def ctrlS():
    win32api.keybd_event(17, 0, 0, 0)  # Ctrl
    win32api.keybd_event(83, 0, 0, 0)  # S
    win32api.keybd_event(17, 0, win32con.KEYEVENTF_KEYUP, 0)
    win32api.keybd_event(83, 0, win32con.KEYEVENTF_KEYUP, 0)
示例#32
0
def buy_stock(stock_id,stock_price,stock_sum):
    if not stock_id:
        os._exit(0)
    if not stock_sum:
        os._exit(0)
    if( not stock_id.isdigit() or not len(stock_id)==6):
        os._exit(0)
    if( not stock_sum.isdigit()):
        os._exit(0)

    #1 先按F1打开买入界面  然后刷新一下

    #卖出界面F2
    win32api.keybd_event(113,0,0,0)	    # F2
    win32api.keybd_event(113,0,win32con.KEYEVENTF_KEYUP,0)  #释放按键
    
    #买入界面F1
    win32api.keybd_event(112,0,0,0)	    # F1
    win32api.keybd_event(112,0,win32con.KEYEVENTF_KEYUP,0)  #释放按键
    time.sleep(0.01)

    #刷新F5
    win32api.keybd_event(116,0,0,0)	    # F5
    win32api.keybd_event(116,0,win32con.KEYEVENTF_KEYUP,0)  #释放按键
    time.sleep(0.01)

    #六遍Backspace按键删除证券代码中的信息
    for i in range(1,8):
        win32api.keybd_event(8,0,0,0)	    # Backspace
        win32api.keybd_event(8,0,win32con.KEYEVENTF_KEYUP,0)  #释放按键
    
    
    #2  输入要买的代码
    inputnum(stock_id)
    #3  按tab切到买入价格
    win32api.keybd_event(9,0,0,0)
    win32api.keybd_event(9,0,win32con.KEYEVENTF_KEYUP,0)
    time.sleep(0.1)
    #输入买入价格
    inputnum(stock_price)

    #4  按tab切换到买入数量
    win32api.keybd_event(9,0,0,0)
    win32api.keybd_event(9,0,win32con.KEYEVENTF_KEYUP,0)
    time.sleep(0.01)
    #5  输入数量
    inputnum(stock_sum)

    #6  点击买入按钮B
    win32api.keybd_event(66,0,0,0)
    win32api.keybd_event(66,0,win32con.KEYEVENTF_KEYUP,0)
    time.sleep(0.1)

    #7  点击确认买入Y
    #win32api.keybd_event(89,0,0,0)
    #win32api.keybd_event(89,0,win32con.KEYEVENTF_KEYUP,0)
    
    #执行完成后打印日志
    #print('买入股票代码:'+stock_id+'  买入价格:'+stock_price+'  买入数量:'+stock_sum)
    print 0
示例#33
0
 def key_event(self, KEY_CODE):
     # 按下
     win32api.keybd_event(KEY_CODE, 0, 0, 0)
     # 抬起
     win32api.keybd_event(KEY_CODE, 0, win32con.KEYEVENTF_KEYUP, 0)
示例#34
0
def huiche():
    win32api.keybd_event(18, 0, 0, 0)  # Alt键位码
    win32api.keybd_event(83, 0, 0, 0)  # s键位码
    win32api.keybd_event(18, 0, win32con.KEYEVENTF_KEYUP, 0)  # 释放按键
    win32api.keybd_event(83, 0, win32con.KEYEVENTF_KEYUP, 0)
示例#35
0
def t2():
    mouse_click(800, 200)
    for c in 'hello':
        win32api.keybd_event(65, 0, 0, 0)  #a键位码是86
        win32api.keybd_event(65, 0, win32con.KEYEVENTF_KEYUP, 0)
def keyUp(keyName):
    win32api.keybd_event(VK_CODE[keyName], 0, win32con.KEYEVENTF_KEYUP, 0)
示例#37
0
def stopMusic():
    win32api.keybd_event(VK_CODE["ctrl"], 0, 0, 0)
    win32api.keybd_event(VK_CODE["alt"], 0, 0, 0)
    win32api.keybd_event(VK_CODE["p"], 0, 0, 0)
    time.sleep(0.1)
    win32api.keybd_event(VK_CODE["p"], 0, win32con.KEYEVENTF_KEYUP, 0)
    win32api.keybd_event(VK_CODE["alt"], 0, win32con.KEYEVENTF_KEYUP, 0)
    win32api.keybd_event(VK_CODE["ctrl"], 0, win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(1)
示例#38
0
def input_base():
    win32api.keybd_event(0x20, 0, 0, 0)
    win32api.keybd_event(0x20, 0, win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(0.01)
示例#39
0
def input_enter():
    win32api.keybd_event(0x0D, 0, 0, 0)
    win32api.keybd_event(0x0D, 0, win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(0.01)
示例#40
0
def paste(os_type):
    if os_type == 'Windows':
        win32api.keybd_event(VK_CODE['ctrl'], 0, 0, 0)
        win32api.keybd_event(VK_CODE['v'], 0, 0, 0)
        win32api.keybd_event(VK_CODE['v'], 0, win32con.KEYEVENTF_KEYUP, 0)
        win32api.keybd_event(VK_CODE['ctrl'], 0, win32con.KEYEVENTF_KEYUP, 0)
        time.sleep(0.01)
    else:
        win32api.keybd_event(VK_CODE['shift'], 0, 0, 0)
        win32api.keybd_event(VK_CODE['ins'], 0, 0, 0)
        win32api.keybd_event(VK_CODE['ins'], 0, win32con.KEYEVENTF_KEYUP, 0)
        win32api.keybd_event(VK_CODE['shift'], 0, win32con.KEYEVENTF_KEYUP, 0)
        time.sleep(0.01)
示例#41
0
def quanbuchedan():
    #撤单界面F3
    win32api.keybd_event(114,0,0,0)	    # F3
    win32api.keybd_event(114,win32con.KEYEVENTF_KEYUP,0)  #释放按键
    time.sleep(0.1)

    #刷新一下
    win32api.keybd_event(116,0,0,0)	    # F5
    win32api.keybd_event(116,win32con.KEYEVENTF_KEYUP,0)  #释放按键
    time.sleep(0.5)

    #按Z全部撤单
    win32api.keybd_event(90,0,0,0)	    # Z
    win32api.keybd_event(90,win32con.KEYEVENTF_KEYUP,0)  #释放按键
    print 0
示例#42
0
import win32con
import win32api
import time

# win32api.keybd_event(91, 0, 0, 0)
# time.sleep(0.1)
# win32api.keybd_event(91, 0, win32con.KEYEVENTF_KEYUP, 0)
while True:
    win32api.keybd_event(91, 0, 0, 0)
    time.sleep(0.1)
    win32api.keybd_event(77, 0, 0, 0)
    time.sleep(0.1)
    win32api.keybd_event(91, 0, win32con.KEYEVENTF_KEYUP, 0)
    win32api.keybd_event(77, 0, win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(3)
示例#43
0
文件: code.py 项目: jwong28/Protobot
def spacePress():

    win32api.keybd_event(0x20,0,0,0)
    time.sleep(.05)
    win32api.keybd_event(0x20,0,win32con.KEYEVENTF_KEYUP,0)
示例#44
0
            print("从第{}次开始采集".format(start))
            break
        else:
            print("超出范围,请重新输入")
    except:
        print("请重新输入")

print("请配置好上位机")
for idx in range(start, max_times):
    input("按下 “DCA1000 ARM” 后按回车开始第{:04d}次采集".format(idx))
    # 显示隐藏窗口
    if (win32gui.IsIconic(hwnd)):
        # win32gui.ShowWindow(hwnd, win32con.SW_SHOWNORMAL)
        win32gui.ShowWindow(hwnd, 4)
        time.sleep(0.5)
    # 需要先对当前窗口发送指令,才能激活特定窗口(win32com的bug)
    win32api.keybd_event(18, 0, 0, 0)  # 按下Alt(ASCII 18)
    win32api.keybd_event(18, 0, win32con.KEYEVENTF_KEYUP, 0)  # 松开Alt(ASCII 18)
    win32gui.SetForegroundWindow(hwnd)  # 置于顶层(目标窗口不能最小化或隐藏)
    win32api.keybd_event(13, 0, 0, 0)  # 按下回车(ASCII 13)
    win32api.keybd_event(13, 0, win32con.KEYEVENTF_KEYUP, 0)  # 松开回车(ASCII 13)
    print("第{:04d}次采集开始...".format(idx))

    # 重命名指定文件
    time.sleep(3)
    for filetype in filetype_list:
        filename = os.path.join(store_dir, filetype)
        os.rename(filename,
                  os.path.join(store_dir, "{:04d}_{}".format(idx, filetype)))

    print("第{:04d}次采集完成并已重命名".format(idx))
示例#45
0
 def run(self):
     """Execute the action"""
     # it works more stable for virtual keys than SendInput
     for inp in self.GetInput():
         win32api.keybd_event(inp.ki.wVk, inp.ki.wScan, inp.ki.dwFlags)
示例#46
0
 def key_input(self, str=''):
     for c in str:
         win32api.keybd_event(self.VK_CODE[c], 0, 0, 0)
         win32api.keybd_event(self.VK_CODE[c], 0, win32con.KEYEVENTF_KEYUP,
                              0)
         time.sleep(0.01)
示例#47
0
def buttonPush(button):
    win32api.keybd_event(KEYMAPS().keymap.get(button, "None"), 0, 0, 0)
    time.sleep(0.20)
    win32api.keybd_event(KEYMAPS().keymap.get(button, "None"), 0,
                         win32con.KEYEVENTF_KEYUP, 0)
    print ">>> Pressing " + button.upper()
示例#48
0
def mainGame(movementInfo):
    score = playerIndex = loopIter = 0
    playerIndexGen = movementInfo['playerIndexGen']
    playerx, playery = int(SCREENWIDTH * 0.2), movementInfo['playery']

    basex = movementInfo['basex']
    baseShift = IMAGES['base'].get_width() - IMAGES['background'].get_width()

    # get 2 new pipes to add to upperPipes lowerPipes list
    newPipe1 = getRandomPipe()
    newPipe2 = getRandomPipe()

    # list of upper pipes
    upperPipes = [
        {
            'x': SCREENWIDTH + 200,
            'y': newPipe1[0]['y']
        },
        {
            'x': SCREENWIDTH + 200 + (SCREENWIDTH / 2),
            'y': newPipe2[0]['y']
        },
    ]

    # list of lowerpipe
    lowerPipes = [
        {
            'x': SCREENWIDTH + 200,
            'y': newPipe1[1]['y']
        },
        {
            'x': SCREENWIDTH + 200 + (SCREENWIDTH / 2),
            'y': newPipe2[1]['y']
        },
    ]

    pipeVelX = -4

    # player velocity, max velocity, downward accleration, accleration on flap
    playerVelY = -9  # player's velocity along Y, default same as playerFlapped
    playerMaxVelY = 10  # max vel along Y, max descend speed
    playerMinVelY = -8  # min vel along Y, max ascend speed
    playerAccY = 1  # players downward accleration
    playerRot = 45  # player's rotation
    playerVelRot = 3  # angular speed
    playerRotThr = 20  # rotation threshold
    playerFlapAcc = -9  # players speed on flapping
    playerFlapped = False  # True when player flaps
    capture = cv2.VideoCapture(0)
    start_time = time.time()
    areaold = 0
    key_relase = True
    while True:
        ha, img = capture.read()
        img = cv2.flip(img, 1)
        cv2.rectangle(img, (426, 50), (640, 350), (170, 170, 0))
        img = img[50:350, 426:640, :]
        cv2.imshow("img", img)
        img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        img = cv2.resize(img, (64, 64)).reshape((1, 64, 64, 1))

        # 0是拳头 1 是手掌
        action = predict(img, sess, x_image, y_, keep_drop)
        if action == 1:
            win32api.keybd_event(38, 0, win32con.KEYEVENTF_KEYUP, 0)  #释放按键
        else:
            win32api.keybd_event(38, 0, 0, 0)
        for event in pygame.event.get():
            if event.type == QUIT or (event.type == KEYDOWN
                                      and event.key == K_ESCAPE):
                pygame.quit()
                sys.exit()
            if event.type == KEYDOWN and (event.key == K_SPACE
                                          or event.key == K_UP):
                # win32api.keybd_event(38,0,win32con.KEYEVENTF_KEYUP,0) #释放按键
                if playery > -2 * IMAGES['player'][0].get_height():
                    playerVelY = playerFlapAcc
                    playerFlapped = True
                    SOUNDS['wing'].play()
                break
        # check for crash here
        crashTest = checkCrash(
            {
                'x': playerx,
                'y': playery,
                'index': playerIndex
            }, upperPipes, lowerPipes)
        if crashTest[0]:
            return {
                'y': playery,
                'groundCrash': crashTest[1],
                'basex': basex,
                'upperPipes': upperPipes,
                'lowerPipes': lowerPipes,
                'score': score,
                'playerVelY': playerVelY,
                'playerRot': playerRot
            }

        # check for score
        playerMidPos = playerx + IMAGES['player'][0].get_width() / 2
        for pipe in upperPipes:
            pipeMidPos = pipe['x'] + IMAGES['pipe'][0].get_width() / 2
            if pipeMidPos <= playerMidPos < pipeMidPos + 4:
                score += 1
                SOUNDS['point'].play()

        # playerIndex basex change
        if (loopIter + 1) % 3 == 0:
            playerIndex = next(playerIndexGen)
        loopIter = (loopIter + 1) % 30
        basex = -((-basex + 100) % baseShift)

        # rotate the player
        if playerRot > -90:
            playerRot -= playerVelRot
        # player's movement
        if playerVelY < playerMaxVelY and not playerFlapped:
            playerVelY += playerAccY
        if playerFlapped:
            playerFlapped = False
            # more rotation to cover the threshold (calculated in visible rotation)
            playerRot = 45
        playerHeight = IMAGES['player'][playerIndex].get_height()
        playery += min(playerVelY, BASEY - playery - playerHeight)

        # move pipes to left
        for uPipe, lPipe in zip(upperPipes, lowerPipes):
            uPipe['x'] += pipeVelX
            lPipe['x'] += pipeVelX

        # add new pipe when first pipe is about to touch left of screen
        if 0 < upperPipes[0]['x'] < 5:
            newPipe = getRandomPipe()
            upperPipes.append(newPipe[0])
            lowerPipes.append(newPipe[1])

        # remove first pipe if its out of the screen
        if upperPipes[0]['x'] < -IMAGES['pipe'][0].get_width():
            upperPipes.pop(0)
            lowerPipes.pop(0)

        # draw sprites
        SCREEN.blit(IMAGES['background'], (0, 0))

        for uPipe, lPipe in zip(upperPipes, lowerPipes):
            SCREEN.blit(IMAGES['pipe'][0], (uPipe['x'], uPipe['y']))
            SCREEN.blit(IMAGES['pipe'][1], (lPipe['x'], lPipe['y']))

        SCREEN.blit(IMAGES['base'], (basex, BASEY))
        # print score so player overlaps the score
        showScore(score)

        # Player rotation has a threshold
        visibleRot = playerRotThr
        if playerRot <= playerRotThr:
            visibleRot = playerRot

        playerSurface = pygame.transform.rotate(IMAGES['player'][playerIndex],
                                                visibleRot)
        SCREEN.blit(playerSurface, (playerx, playery))

        pygame.display.update()
        FPSCLOCK.tick(FPS)
        cv2.waitKey(FPS)
def keyDown(keyName):
    win32api.keybd_event(VK_CODE[keyName], 0, 0, 0)
示例#50
0
def key_zuhe_input(str1, str2):
    win32api.keybd_event(str1, 0, 0, 0)
    win32api.keybd_event(str2, 0, 0, 0)
    win32api.keybd_event(str1, 0, win32con.KEYEVENTF_KEYUP, 0)
    win32api.keybd_event(str2, 0, win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(0.01)
示例#51
0
def onKeyboardEvent(event):
    '''print "MessageName:", event.MessageName     
    print "Message:", event.Message     
    print "Time:", event.Time     
    print "Window:", event.Window     
    print "WindowName:", event.WindowName     
    print "Ascii:", event.Ascii, chr(event.Ascii)     
    print "Key:", event.Key     
    print "KeyID:", event.KeyID     
    print "ScanCode:", event.ScanCode     
    print "Extended:", event.Extended     
    print "Injected:", event.Injected     
    print "Alt", event.Alt     
    print "Transition", event.Transition     
    print "---"'''
    d = 0.06
    t = 0.06
    t2 = 0.02
    global on
    if event.Key == 'Oem_3' and event.MessageName == 'key up':
        if on == True:
            on = False
        else:
            on = True
    if on == False:
        return True
    #print event.Key
    global down
    if event.Key == 'Lshift' and event.MessageName == 'key up':
        down = False
    if event.MessageName == 'key down':
        if event.Key == 'Lshift' and event.MessageName == 'key down' and down == False:
            down = True
            return True
        if event.Key == 'S':
            k = PyKeyboard()
            vec2 = vec
            newv = [0, 0]
            newv[0] = vec2[1]
            newv[1] = vec2[0] * (-1)
            addvec = [(newv[0] + vec[0]) * 0.5, (newv[1] + vec[1]) * 0.5]
            #newv[1]=math.sin(math.atan(vec2[1]/vec2[0])+math.pi/4)*(vec2[0]*vec2[0]+vec2[1]*vec2[1])**0.5
            pyautogui.moveRel(addvec[0] - vec2[0],
                              addvec[1] - vec2[1],
                              duration=d,
                              tween=pyautogui.linear)
            #k.tap_key('f')
            time.sleep(t2)
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(t2)
            pyautogui.moveRel(addvec[0] * (-1),
                              addvec[1] * (-1),
                              duration=d,
                              tween=pyautogui.linear)
            #k.tap_key('f')
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(2 * t2)
            pyautogui.moveRel(vec2[0] - addvec[0],
                              vec2[1] - addvec[1],
                              duration=d,
                              tween=pyautogui.linear)
            #k.tap_key('k')
            time.sleep(t)
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(t)
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(t)
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(t)
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            '''win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(t)
            win32api.keybd_event(0x46, 0, 0, 0)
            time.sleep(t)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(t)
            win32api.keybd_event(0x46, 0, 0, 0)
            time.sleep(t)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)'''
            return True
        if event.Key == 'D':
            k = PyKeyboard()
            vec2 = vec
            newv = [0, 0]
            newv[0] = vec2[1] * (-1)
            newv[1] = vec2[0]
            addvec = [(newv[0] + vec[0]) * 0.5, (newv[1] + vec[1]) * 0.5]
            #newv[1]=math.sin(math.atan(vec2[1]/vec2[0])+math.pi/4)*(vec2[0]*vec2[0]+vec2[1]*vec2[1])**0.5
            pyautogui.moveRel(addvec[0] - vec2[0],
                              addvec[1] - vec2[1],
                              duration=d,
                              tween=pyautogui.linear)
            #k.tap_key('f')
            time.sleep(t2)
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(t2)
            pyautogui.moveRel(addvec[0] * (-1),
                              addvec[1] * (-1),
                              duration=d,
                              tween=pyautogui.linear)
            #k.tap_key('f')
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(2 * t2)
            pyautogui.moveRel(vec2[0] - addvec[0],
                              vec2[1] - addvec[1],
                              duration=d,
                              tween=pyautogui.linear)
            time.sleep(t)
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(t)
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(t)
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(t)
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            return True
        if event.Key == 'W':
            k = PyKeyboard()
            vec2 = vec
            newvA = [0, 0]
            newvB = [0, 0]
            newvA[0] = vec2[1] * (-1)
            newvA[1] = vec2[0]
            newvB[0] = vec2[1]
            newvB[1] = vec2[0] * (-1)
            pyautogui.moveRel(newvA[0] - vec2[0],
                              newvA[1] - vec2[1],
                              duration=d,
                              tween=pyautogui.linear)
            #k.tap_key('f')
            time.sleep(t2)
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(t2)
            pyautogui.moveRel(newvB[0] - newvA[0],
                              newvB[1] - newvA[1],
                              duration=d,
                              tween=pyautogui.linear)
            #k.tap_key('f')
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(2 * t2)
            pyautogui.moveRel(vec2[0] - newvB[0],
                              vec2[1] - newvB[1],
                              duration=d,
                              tween=pyautogui.linear)
            time.sleep(t)
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(t)
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(t)
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(t)
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            return True
        if event.Key == 'A':
            k = PyKeyboard()
            vec2 = vec
            newvA = [0, 0]
            newvB = [0, 0]
            newvA[0] = vec2[1] * (-1) + 0.1 * vec2[0]
            newvA[1] = vec2[0] + 0.1 * vec2[1]
            newvB[0] = vec2[1] + 0.1 * vec2[0]
            newvB[1] = vec2[0] * (-1) + 0.1 * vec2[1]
            pyautogui.moveRel(newvA[0] - vec2[0],
                              newvA[1] - vec2[1],
                              duration=d,
                              tween=pyautogui.linear)
            #k.tap_key('f')
            time.sleep(t2)
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(t2)
            pyautogui.moveRel(newvB[0] - newvA[0],
                              newvB[1] - newvA[1],
                              duration=d,
                              tween=pyautogui.linear)
            #k.tap_key('f')
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(2 * t2)
            pyautogui.moveRel(vec2[0] - newvB[0],
                              vec2[1] - newvB[1],
                              duration=d,
                              tween=pyautogui.linear)
            time.sleep(t)
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(t)
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(t)
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            time.sleep(t)
            win32api.keybd_event(0x46, 0, 0, 0)
            win32api.keybd_event(0x46, 0, win32con.KEYEVENTF_KEYUP, 0)
            return True
        ''' if event.Key == 'Lshift':
        if event.MessageName=='key up':
            k=PyKeyboard()
            k.tap_key('l')'''
        return True
    return True
示例#52
0
def key_input(input_str=''):
    if re.search(
            "^F\d+$",
            input_str,
    ):
        win32api.keybd_event(VK_CODE[input_str], 0, 0, 0)
        win32api.keybd_event(VK_CODE[input_str], 0, win32con.KEYEVENTF_KEYUP,
                             0)
        return
    for c in input_str:
        if c == '_':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['-'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['-'], 0, win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
        else:
            win32api.keybd_event(VK_CODE[c], 0, 0, 0)
            win32api.keybd_event(VK_CODE[c], 0, win32con.KEYEVENTF_KEYUP, 0)
        time.sleep(0.03)
示例#53
0
def zhanTie():
    win32api.keybd_event(17, 0, 0, 0)  # ctrl键位码是17
    win32api.keybd_event(86, 0, 0, 0)  # v键位码是86
    win32api.keybd_event(86, 0, win32con.KEYEVENTF_KEYUP, 0)  # 释放按键
    win32api.keybd_event(17, 0, win32con.KEYEVENTF_KEYUP, 0)
示例#54
0
def nextMusic():
    win32api.keybd_event(VK_CODE["ctrl"], 0, 0, 0)
    win32api.keybd_event(VK_CODE["alt"], 0, 0, 0)
    win32api.keybd_event(VK_CODE["right_arrow"], 0, 0, 0)
    time.sleep(0.1)
    win32api.keybd_event(VK_CODE["right_arrow"], 0, win32con.KEYEVENTF_KEYUP,
                         0)
    win32api.keybd_event(VK_CODE["alt"], 0, win32con.KEYEVENTF_KEYUP, 0)
    win32api.keybd_event(VK_CODE["ctrl"], 0, win32con.KEYEVENTF_KEYUP, 0)
    time.sleep(1)
示例#55
0
        formatzijin.append(win32gui.GetWindowText(zijin[11]))#股票市值
        formatzijin.append(win32gui.GetWindowText(zijin[12]))#总 资 产
        print(formatzijin[0]+'#'+formatzijin[1]+'#'+formatzijin[2]+'#'+formatzijin[3]+'#'+formatzijin[4]+'#'+formatzijin[5])    
    
    
#获取句柄

    
global hwnd
hwnd = win32gui.FindWindow(None, titlename)
if(hwnd>0):
    #获得焦点
    win32gui.SetForegroundWindow(hwnd)
    time.sleep(0.1)
    #买入界面F1
    win32api.keybd_event(112,0,0,0)	    # F5
    win32api.keybd_event(112,0,win32con.KEYEVENTF_KEYUP,0)  #释放按键

    #刷新F5
    #win32api.keybd_event(116,0,0,0)	    # F5
    #win32api.keybd_event(116,0,win32con.KEYEVENTF_KEYUP,0)  #释放按键
    #time.sleep(0.5)

    ##状态参数  1:买入 0:卖出  3:全部撤单  4:刷新  5:查询资金 
    if(sys.argv[1]=='1'):
        buy_stock(sys.argv[2],sys.argv[3],sys.argv[4])
    elif(sys.argv[1]=='0'):
        sell_stock(sys.argv[2],sys.argv[3],sys.argv[4])
    elif(sys.argv[1]=='3'):
        quanbuchedan()    
    elif(sys.argv[1]=='4'):
示例#56
0
def moveUp():
    win32api.keybd_event(win32con.VK_UP, 0, 0x0000, 0)
    time.sleep(sleepTime)
    win32api.keybd_event(win32con.VK_UP, 0, win32con.KEYEVENTF_KEYUP, 0)
示例#57
0
            for prob, dis_reward in zip(prob_pool, discounted_rewards):
                policy_loss.append(-prob * dis_reward)

            loss_fn = torch.stack(policy_loss).sum()
            loss_fn.backward()
            optimizer.step()

            del prob_pool[:]
            del reward_pool[:]

            running_reward = reward_sum if running_reward is None else running_reward * 0.99 + reward_sum * 0.01
            print(
                f'Batch reward total was ${reward_sum} running mean: #{running_reward}'
            )
            torch.save(policy.state_dict(), model_name)
            reward_sum = 0
            prev_x = None
            curr_x, reward, done = env.reload()
            last_reward = 0


if __name__ == '__main__':
    win32api.keybd_event(0xA4, 0, 0x00, 0)
    win32api.keybd_event(0x09, 0, 0x00, 0)
    win32api.keybd_event(0xA4, 0, 0x02, 0)
    win32api.keybd_event(0x09, 0, 0x02, 0)
    time.sleep(1)
    win32api.keybd_event(0x20, 0, 0x00, 0)
    win32api.keybd_event(0x20, 0, 0x02, 0)
    time.sleep(2.4)
    main()
def typer(string=None, *args):
    ##    time.sleep(4)
    for i in string:
        if i == ' ':
            win32api.keybd_event(VK_CODE['spacebar'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['spacebar'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)

        elif i == '!':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['1'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['1'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == '@':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['2'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['2'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == '{':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['['], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['['], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == '?':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['/'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['/'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == ':':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE[';'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE[';'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == '"':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['\''], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['\''], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == '}':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE[']'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE[']'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == '#':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['3'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['3'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == '$':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['4'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['4'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == '%':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['5'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['5'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == '^':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['6'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['6'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == '&':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['7'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['7'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == '*':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['8'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['8'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == '(':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['9'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['9'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == ')':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['0'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['0'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == '_':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['-'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['-'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == '=':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['+'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['+'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == '~':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['`'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['`'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == '<':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE[','], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE[','], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == '>':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['.'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['.'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'A':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['a'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['a'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'B':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['b'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['b'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'C':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['c'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['c'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'D':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['d'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['d'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'E':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['e'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['e'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'F':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['f'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['f'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'G':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['g'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['g'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'H':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['h'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['h'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'I':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['i'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['i'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'J':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['j'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['j'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'K':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['k'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['k'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'L':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['l'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['l'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'M':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['m'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['m'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'N':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['n'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['n'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'O':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['o'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['o'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'P':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['p'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['p'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'Q':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['q'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['q'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'R':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['r'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['r'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'S':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['s'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['s'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'T':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['t'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['t'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'U':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['u'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['u'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'V':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['v'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['v'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'W':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['w'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['w'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'X':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['x'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['x'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'Y':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['y'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['y'], 0, win32con.KEYEVENTF_KEYUP, 0)

        elif i == 'Z':
            win32api.keybd_event(VK_CODE['left_shift'], 0, 0, 0)
            win32api.keybd_event(VK_CODE['z'], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE['left_shift'], 0,
                                 win32con.KEYEVENTF_KEYUP, 0)
            win32api.keybd_event(VK_CODE['z'], 0, win32con.KEYEVENTF_KEYUP, 0)

        else:
            win32api.keybd_event(VK_CODE[i], 0, 0, 0)
            time.sleep(.05)
            win32api.keybd_event(VK_CODE[i], 0, win32con.KEYEVENTF_KEYUP, 0)
示例#59
0
def hardDrop():
    win32api.keybd_event(win32con.VK_SPACE, 0, 0x0000, 0)
    time.sleep(sleepTime)
    win32api.keybd_event(win32con.VK_SPACE, 0, win32con.KEYEVENTF_KEYUP, 0)
示例#60
0
文件: code.py 项目: jwong28/Protobot
def rightUp():
    win32api.keybd_event(0x27,0,win32con.KEYEVENTF_KEYUP,0)
    time.sleep(.01)