Python win32con.KEYEVENTF_KEYUP Examples
The following are 11
code examples of win32con.KEYEVENTF_KEYUP().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
win32con
, or try the search function
.
Example #1
Source File: game.py From twitch-plays with MIT License | 6 votes |
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)
Example #2
Source File: sendinput.py From dragonfly with GNU Lesser General Public License v3.0 | 6 votes |
def __init__(self, virtual_keycode, down, scancode=-1, layout=None): """Initialize structure based on key type.""" if scancode == -1: if not layout: scancode = windll.user32.MapVirtualKeyW(virtual_keycode, 0) else: # Assume that 'layout' is a keyboard layout (HKL). scancode = windll.user32.MapVirtualKeyExW(virtual_keycode, 0, layout) flags = 0 if virtual_keycode == 0: flags |= 4 # KEYEVENTF_UNICODE else: if virtual_keycode not in self.soft_keys: flags |= 8 # KEYEVENTF_SCANCODE if virtual_keycode in self.extended_keys: flags |= win32con.KEYEVENTF_EXTENDEDKEY if not down: flags |= win32con.KEYEVENTF_KEYUP extra = pointer(c_ulong(0)) # print(virtual_keycode, scancode, flags, 0, extra) Structure.__init__(self, virtual_keycode, scancode, flags, 0, extra)
Example #3
Source File: use_keyboard_and_mouse.py From Automatic-minesweeping with MIT License | 5 votes |
def f2(self): key_f2 = 113 # f2对应的键盘输入值 keybd_event(key_f2, 0, 0, 0) keybd_event(key_f2, 0, KEYEVENTF_KEYUP, 0) # 截图
Example #4
Source File: ctypesinput.py From Airtest with Apache License 2.0 | 5 votes |
def key_release(key): """Simulates a key release event. Sends a scancode to the computer to report which key has been released. Some games use DirectInput devices, and respond only to scancodes, not virtual key codes. You can simulate DirectInput key releases using this method. A call to the key_release(...) method usually follows a call to the key_press(..) method of the same key. :param key: A string indicating which key to be released. """ try: key_name = key.upper() except AttributeError: raise ValueError('invalid literal for key_release(): {}'.format(key)) try: hex_code = KEYS[key_name] except KeyError: pass else: flags = KEYEVENTF_SCANCODE | win32con.KEYEVENTF_KEYUP send_keyboard_input(hex_code, flags) return try: hex_code = EXTENDED_KEYS[key_name] except KeyError: raise ValueError('invalid literal for key_release(): {}'.format(key)) else: flags = (win32con.KEYEVENTF_EXTENDEDKEY | KEYEVENTF_SCANCODE | win32con.KEYEVENTF_KEYUP) send_keyboard_input(hex_code, flags)
Example #5
Source File: rescaletime.py From cross3d with MIT License | 5 votes |
def pressKey(self, key): keybd_event(self.virtualKeyMap[key], self.hardwareKeyMap[key], 0, 0) keybd_event(self.virtualKeyMap[key], self.hardwareKeyMap[key], win32con.KEYEVENTF_KEYUP, 0)
Example #6
Source File: sendinput.py From dragonfly with GNU Lesser General Public License v3.0 | 5 votes |
def __init__(self, virtual_keycode, down): scancode = windll.user32.MapVirtualKeyA(virtual_keycode, 0) flags = 0 if not down: flags |= win32con.KEYEVENTF_KEYUP if virtual_keycode in self.extended_keys: flags |= win32con.KEYEVENTF_EXTENDEDKEY extra = pointer(c_ulong(0)) Structure.__init__(self, virtual_keycode, scancode, flags, 0, extra)
Example #7
Source File: windows.py From airtest with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #8
Source File: code_editor.py From equant with GNU General Public License v2.0 | 5 votes |
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) # 常规函数
Example #9
Source File: sampler.py From DeepWarp with Apache License 2.0 | 4 votes |
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
Example #10
Source File: studiomaxscene.py From cross3d with MIT License | 4 votes |
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
Example #11
Source File: Email My PC.py From Email_My_PC with MIT License | 4 votes |
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 #设置开机启动快捷方式