當前位置: 首頁>>代碼示例>>Python>>正文


Python win32api.keybd_event方法代碼示例

本文整理匯總了Python中win32api.keybd_event方法的典型用法代碼示例。如果您正苦於以下問題:Python win32api.keybd_event方法的具體用法?Python win32api.keybd_event怎麽用?Python win32api.keybd_event使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在win32api的用法示例。


在下文中一共展示了win32api.keybd_event方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: sample_one_person

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import keybd_event [as 別名]
def sample_one_person(n, num_x=5, num_y=5):
    save_path = 'D:/UnityEyes_Windows/imgs'
    if os.path.exists(save_path) == False:
        os.mkdir(save_path)

    # reset
    win32gui.SendMessage(handle, win32con.WM_ACTIVATE, win32con.WA_ACTIVE, 0)
    center_x = (clt_left + clt_right) // 2
    center_y = (clt_top + clt_bottom) // 2
    win32api.SetCursorPos([center_x, center_y])

    # press 'L'
    win32api.keybd_event(KEY_LIGHT, 0, 0, 0)  # key down
    time.sleep(1)
    win32api.keybd_event(KEY_LIGHT, 0, win32con.KEYEVENTF_KEYUP, 0)  # key up
    # press 'R'
    win32api.keybd_event(KEY_RANDOM, 0, 0, 0)  # key down
    time.sleep(1)
    win32api.keybd_event(KEY_RANDOM, 0, win32con.KEYEVENTF_KEYUP, 0)  # key up

    # number of points for vertical and horizontal
    # num_x, num_y = 5, 5

    step_x, step_y = width // (num_x + 1), height // (num_y + 1)
    for i in range(1, num_y+1):
        for j in range(1, num_x+1):
            x = clt_left + j * step_x
            y = clt_top + i * step_y
            print('{},{}'.format(x, y))
            win32api.mouse_event(win32con.MOUSEEVENTF_MIDDLEDOWN, 0, 0, 0, 0)
            win32api.SetCursorPos([x, y])
            win32api.mouse_event(win32con.MOUSEEVENTF_MIDDLEUP, 0, 0, 0, 0)
            time.sleep(0.5)
            win32api.keybd_event(KEY_SAVE, 0, 0, 0) # key down
            win32api.keybd_event(KEY_SAVE, 0, win32con.KEYEVENTF_KEYUP, 0)  # key up 
開發者ID:BlueWinters,項目名稱:DeepWarp,代碼行數:37,代碼來源:sampler.py

示例2: push_button

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import keybd_event [as 別名]
def push_button(self, button):
        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) 
開發者ID:aidanrwt,項目名稱:twitch-plays,代碼行數:6,代碼來源:game.py

示例3: type

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import keybd_event [as 別名]
def type(self, text):
        ''' Type text into device '''
        
        for c in text:
            if c in ShiftCodes:  #judge the character is a capital letter or not; 16 is the value of shift
                win32api.keybd_event(16,win32api.MapVirtualKey(16,0),0,0)
                win32api.keybd_event(ShiftCodes[c],win32api.MapVirtualKey(ShiftCodes[c],0),0,0)
                win32api.keybd_event(16,win32api.MapVirtualKey(16,0),win32con.KEYEVENTF_KEYUP,0)
                win32api.keybd_event(ShiftCodes[c],win32api.MapVirtualKey(ShiftCodes[c],0),win32con.KEYEVENTF_KEYUP,0)
            elif c in OriginalCodes:    #judge the character is a capital letter or not
                win32api.keybd_event(OriginalCodes[c],win32api.MapVirtualKey(OriginalCodes[c],0),0,0)
                win32api.keybd_event(OriginalCodes[c],win32api.MapVirtualKey(OriginalCodes[c],0),win32con.KEYEVENTF_KEYUP,0) 
開發者ID:NetEase,項目名稱:airtest,代碼行數:14,代碼來源:windows.py

示例4: sendKeyEvent

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import keybd_event [as 別名]
def sendKeyEvent(key, command):
    win32api.keybd_event(key, 0, command, 0)
    time.sleep(0.2) 
開發者ID:drongh,項目名稱:pyAutoTrading,代碼行數:5,代碼來源:winguiauto.py

示例5: do_key_event

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import keybd_event [as 別名]
def do_key_event(self, keys, is_group):
        for key in keys:
            win32api.keybd_event(int(key), 0, 0, 0)
            if not is_group:
                win32api.keybd_event(int(key), 0, win32con.KEYEVENTF_KEYUP, 0)

        if not is_group:
            return
        keys.reverse()
        for key in keys:
            win32api.keybd_event(int(key), 0, win32con.KEYEVENTF_KEYUP, 0)


# 常規函數 
開發者ID:epolestar,項目名稱:equant,代碼行數:16,代碼來源:code_editor.py

示例6: toggle_play

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import keybd_event [as 別名]
def toggle_play():
    win32api.keybd_event(VK_MEDIA_PLAY_PAUSE, 0, 0, 0) 
開發者ID:roligheten,項目名稱:AndroidMediaControlsWindows,代碼行數:4,代碼來源:media_controls.py

示例7: button_event

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import keybd_event [as 別名]
def button_event(content):
	key_table = {'BACKSPACE':8, 'TAB':9, 'TABLE':9, 'CLEAR':12, 'ENTER':13, 'SHIFT':16, 'CTRL':17, 
		'CONTROL':17, 'ALT':18, 'ALTER':18, 'PAUSE':19, 'BREAK':19, 'CAPSLK':20, 'CAPSLOCK':20, 'ESC':27, 
		'SPACE':32, 'SPACEBAR':32, 'PGUP':33, 'PAGEUP':33, 'PGDN':34, 'PAGEDOWN':34, 'END':35, 'HOME':36, 
		'LEFT':37, 'UP':38, 'RIGHT':39, 'DOWN':40, 'SELECT':41, 'PRTSC':42, 'PRINTSCREEN':42, 'SYSRQ':42, 
		'SYSTEMREQUEST':42, 'EXECUTE':43, 'SNAPSHOT':44, 'INSERT':45, 'DELETE':46, 'HELP':47, 'WIN':91, 
		'WINDOWS':91, 'F1':112, 'F2':113, 'F3':114, 'F4':115, 'F5':116, 'F6':117, 'F7':118, 'F8':119, 
		'F9':120, 'F10':121, 'F11':122, 'F12':123, 'F13':124, 'F14':125, 'F15':126, 'F16':127, 'NMLK':144, 
		'NUMLK':144, 'NUMLOCK':144, 'SCRLK':145, 'SCROLLLOCK':145, 'LEFTCLICK':999, 'RIGHTCLICK':1000}
	unrecognized = ''
	key_values = []
	keys = content.split('+')
	for key in keys:
		raw_key = key
		key = key.strip().replace(' ','').upper()
		if key in key_table:
			key_values.append(key_table.get(key))
		elif len(key) == 1:
			key_values.append(ord(key))
		else:
			if key != '':
				unrecognized = raw_key
	for key_value in key_values:
		if key_value == 999:
			win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
		elif key_value == 1000:
			win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, 0, 0, 0, 0)
		else:
			win32api.keybd_event(key_value, 0, 0, 0)
		time.sleep(1)
	for i in range(len(key_values)-1, -1, -1):
		if key_value == 999:
			win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
		elif key_value == 1000:
			win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, 0, 0, 0, 0)
		else:
			win32api.keybd_event(key_values[i], 0, win32con.KEYEVENTF_KEYUP, 0)
		time.sleep(1)
	return unrecognized

#設置開機啟動快捷方式 
開發者ID:Jackeriss,項目名稱:Email_My_PC,代碼行數:43,代碼來源:Email My PC.py

示例8: importFBX

# 需要導入模塊: import win32api [as 別名]
# 或者: from win32api import keybd_event [as 別名]
def importFBX(self, path, showUI=False, **kwargs):

		# Setting up presets.
		presetPaths = self._fbxIOPresetPaths(action='import')
		templatePath = os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'templates', 'fbx_import_preset.pytempl'))

		# Setting up the FBX presets.
		self._setupFBXIOPresets(presetPaths, templatePath, **{'user': getpass.getuser()})

		# We always show UI in debug mode.
		showUI = True if cross3d.debugLevel >= cross3d.constants.DebugLevels.Mid else showUI

		# If the preset has been modified since the last export, we make sure to reload ours by showing the UI.
		if showUI or (presetPaths and os.path.getmtime(presetPaths[0]) > self._fbxIOPresetModifiedTime + 100):

			# If the user did not want to see the UI, we prepare some callbacks that will press the enter key for him.
			if not showUI:

				# Creating a method that presses enter.
				def pressEnter():
					win32api.keybd_event(0x0D, 0x0D, 0, 0)
					win32api.keybd_event(0x0D, 0x0D, win32con.KEYEVENTF_KEYUP, 0)

				# There will be a prompt for the FBX options.
				QTimer.singleShot(200, pressEnter)

				# There might be a second prompt if the file needs to be overwritten.
				if os.path.exists(path):
					QTimer.singleShot(400, pressEnter)

			# Exporting showin the UI.
			mxs.importfile(path)

		else:
			# Calling the FBX exporter without GUI.
			mxs.importfile(path, mxs.pyhelper.namify("noPrompt"))

		# Restoring presets.
		self._restoreFBXIOPresets()

		# TODO: Softimage returns a model. Here we return a boolean. Do we want to make imported FBX into models or maybe return a list of objects?
		return True 
開發者ID:blurstudio,項目名稱:cross3d,代碼行數:44,代碼來源:studiomaxscene.py


注:本文中的win32api.keybd_event方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。