当前位置: 首页>>代码示例>>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;未经允许,请勿转载。