当前位置: 首页>>代码示例>>Python>>正文


Python win32api.keybd_event函数代码示例

本文整理汇总了Python中win32api.keybd_event函数的典型用法代码示例。如果您正苦于以下问题:Python keybd_event函数的具体用法?Python keybd_event怎么用?Python keybd_event使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了keybd_event函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: clickKey

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)
开发者ID:dhillonsh,项目名称:QWOP,代码行数:7,代码来源:QWOP.py

示例2: main

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])
开发者ID:silviachyou,项目名称:Candy-Crush-AI,代码行数:34,代码来源:final.py

示例3: test_topic6

 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")
开发者ID:mercynoo,项目名称:PC-automation-kqc,代码行数:28,代码来源:kqc_topic6.py

示例4: t3

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)
开发者ID:jszheng,项目名称:PySnippet,代码行数:7,代码来源:mouse_move.py

示例5: keyEventMap

 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)
开发者ID:HaHaDog,项目名称:Poodah,代码行数:29,代码来源:__init__.py

示例6: SendToRConsole

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)
开发者ID:zhenbinwu,项目名称:benwu,代码行数:26,代码来源:windows.py

示例7: jump

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)
开发者ID:Didriksson,项目名称:GoogleGameBeater,代码行数:7,代码来源:GoogleGame.py

示例8: push_button

 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:])    
开发者ID:cicero225,项目名称:twitch-plays,代码行数:31,代码来源:game.py

示例9: keyCombo

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)
开发者ID:yezhiquan2007,项目名称:Stuff,代码行数:7,代码来源:hkUtils.py

示例10: genEvent

 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) 
开发者ID:Tudor-B,项目名称:GamepadHID,代码行数:27,代码来源:Winterface.py

示例11: pressKey

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)
开发者ID:JDongian,项目名称:Neo-Helper,代码行数:7,代码来源:NeoAid.py

示例12: pushButtons

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)
开发者ID:tcamenzi,项目名称:TetrisAI_old,代码行数:30,代码来源:OnlineTetris.py

示例13: winEnumHandler

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)  
开发者ID:07101994,项目名称:apps-1,代码行数:29,代码来源:pywin32_test.py

示例14: key

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)
开发者ID:xk19yahoo,项目名称:SimulateKeyboard,代码行数:7,代码来源:simulate_keyboard.py

示例15: fake_key

 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)
开发者ID:Brainiarc7,项目名称:xpra,代码行数:7,代码来源:shadow_server.py


注:本文中的win32api.keybd_event函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。