Python win32con.WM_KEYDOWN Examples

The following are 12 code examples of win32con.WM_KEYDOWN(). 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: inputs.py    From NGU-scripts with GNU Lesser General Public License v3.0 10 votes vote down vote up
def ctrl_click(x :int, y :int) -> None:
        """Clicks at pixel x, y while simulating the CTRL button to be down."""
        x += Window.x
        y += Window.y
        lParam = win32api.MAKELONG(x, y)
        while (win32api.GetKeyState(wcon.VK_CONTROL) < 0 or
               win32api.GetKeyState(wcon.VK_SHIFT) < 0 or
               win32api.GetKeyState(wcon.VK_MENU) < 0):
            time.sleep(0.005)

        win32gui.PostMessage(Window.id, wcon.WM_KEYDOWN, wcon.VK_CONTROL, 0)
        win32gui.PostMessage(Window.id, wcon.WM_LBUTTONDOWN,
                             wcon.MK_LBUTTON, lParam)
        win32gui.PostMessage(Window.id, wcon.WM_LBUTTONUP,
                             wcon.MK_LBUTTON, lParam)
        win32gui.PostMessage(Window.id, wcon.WM_KEYUP, wcon.VK_CONTROL, 0)
        time.sleep(userset.MEDIUM_SLEEP) 
Example #2
Source File: debugger.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def CreateWindow(self, parent):
		list = self
		style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_BORDER | commctrl.LVS_EDITLABELS | commctrl.LVS_REPORT
		self._obj_.CreateWindow(style, self.GetDefRect(), parent, win32ui.IDC_LIST1)
		self.HookMessage(self.OnKeyDown, win32con.WM_KEYDOWN)
		self.HookMessage(self.OnKeyDown, win32con.WM_SYSKEYDOWN)
		list = self
		title, width = self.columns[0]
		itemDetails = (commctrl.LVCFMT_LEFT, width, title, 0)
		list.InsertColumn(0, itemDetails)
		col = 1
		for title, width in self.columns[1:]:
			col = col + 1
			itemDetails = (commctrl.LVCFMT_LEFT, width, title, 0)
			list.InsertColumn(col, itemDetails)
		parent.HookNotify(self.OnListEndLabelEdit, LVN_ENDLABELEDIT)
		parent.HookNotify(self.OnItemRightClick, commctrl.NM_RCLICK)
		parent.HookNotify(self.OnItemDoubleClick, commctrl.NM_DBLCLK) 
Example #3
Source File: editor.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def HookHandlers(self):	# children can override, but should still call me!
#		self.HookAllKeyStrokes(self.OnKey)
		self.HookMessage(self.OnCheckExternalDocumentUpdated,MSG_CHECK_EXTERNAL_FILE)
		self.HookMessage(self.OnRClick,win32con.WM_RBUTTONDOWN)
		self.HookMessage(self.OnSetFocus, win32con.WM_SETFOCUS)
		self.HookMessage(self.OnKeyDown, win32con.WM_KEYDOWN)
		self.HookKeyStroke(self.OnKeyCtrlY, 25)	# ^Y
		self.HookKeyStroke(self.OnKeyCtrlG, 7)	# ^G
		self.HookKeyStroke(self.OnKeyTab, 9)	# TAB
		self.HookKeyStroke(self.OnKeyEnter, 13) # Enter
		self.HookCommand(self.OnCmdLocateFile, ID_LOCATE_FILE)
		self.HookCommand(self.OnCmdGotoLine, ID_GOTO_LINE)
		self.HookCommand(self.OnEditPaste, afxres.ID_EDIT_PASTE)
		self.HookCommand(self.OnEditCut, afxres.ID_EDIT_CUT)

	# Hook Handlers 
Example #4
Source File: inputs.py    From NGU-scripts with GNU Lesser General Public License v3.0 5 votes vote down vote up
def send_arrow_press(left :bool) -> None:
        """Sends either a left or right arrow key press"""
        if left: key = wcon.VK_LEFT
        else   : key = wcon.VK_RIGHT
        
        win32gui.PostMessage(Window.id, wcon.WM_KEYDOWN, key, 0)
        time.sleep(0.05)
        win32gui.PostMessage(Window.id, wcon.WM_KEYUP, key, 0)
        time.sleep(0.05) 
Example #5
Source File: inputs.py    From NGU-scripts with GNU Lesser General Public License v3.0 5 votes vote down vote up
def send_string(string :str) -> None:
        """Send one or multiple characters to the Window."""
        # Ensure it's a string by converting it to a string
        if isinstance(string, float):
            string = int(string)
        for c in str(string):
            # Make sure no key modifier is pressed
            while (win32api.GetKeyState(wcon.VK_CONTROL) < 0 or
                   win32api.GetKeyState(wcon.VK_SHIFT)   < 0 or
                   win32api.GetKeyState(wcon.VK_MENU)    < 0):
                time.sleep(0.005)
            
            vkc = win32api.VkKeyScan(c)  # Get virtual key code for character c
            # Only one keyup or keydown event needs to be sent
            win32gui.PostMessage(Window.id, wcon.WM_KEYDOWN, vkc, 0) 
Example #6
Source File: debugger.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def CreateWindow(self, parent):
		style = win32con.WS_CHILD | win32con.WS_VISIBLE | win32con.WS_BORDER | commctrl.TVS_HASLINES | commctrl.TVS_LINESATROOT | commctrl.TVS_HASBUTTONS
		self._obj_.CreateWindow(style, self.GetDefRect(), parent, win32ui.IDC_LIST1)
		self.HookMessage(self.OnKeyDown, win32con.WM_KEYDOWN)
		self.HookMessage(self.OnKeyDown, win32con.WM_SYSKEYDOWN)
		self.list.HierInit (parent, self)
		self.listOK = 0 # delayed setup
		#self.list.Setup() 
Example #7
Source File: view.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def HookHandlers(self):
		# Create events for all the menu names.
		for name, val in event_commands:
#			handler = lambda id, code, tosend=val, parent=parent: parent.OnCommand(tosend, 0) and 0
			self.bindings.bind(name, None, cid=val)

		# Hook commands that do nothing other than send Scintilla messages.
		for command, reflection in command_reflectors:
			handler = lambda id, code, ss=self.SendScintilla, tosend=reflection: ss(tosend) and 0
			self.HookCommand(handler, command)

		self.HookCommand(self.OnCmdViewWS, win32ui.ID_VIEW_WHITESPACE)
		self.HookCommandUpdate(self.OnUpdateViewWS, win32ui.ID_VIEW_WHITESPACE)
		self.HookCommand(self.OnCmdViewIndentationGuides, win32ui.ID_VIEW_INDENTATIONGUIDES)
		self.HookCommandUpdate(self.OnUpdateViewIndentationGuides, win32ui.ID_VIEW_INDENTATIONGUIDES)
		self.HookCommand(self.OnCmdViewRightEdge, win32ui.ID_VIEW_RIGHT_EDGE)
		self.HookCommandUpdate(self.OnUpdateViewRightEdge, win32ui.ID_VIEW_RIGHT_EDGE)
		self.HookCommand(self.OnCmdViewEOL, win32ui.ID_VIEW_EOL)
		self.HookCommandUpdate(self.OnUpdateViewEOL, win32ui.ID_VIEW_EOL)
		self.HookCommand(self.OnCmdViewFixedFont, win32ui.ID_VIEW_FIXED_FONT)
		self.HookCommandUpdate(self.OnUpdateViewFixedFont, win32ui.ID_VIEW_FIXED_FONT)
		self.HookCommand(self.OnCmdFileLocate, win32ui.ID_FILE_LOCATE)
		self.HookCommand(self.OnCmdEditFind, win32ui.ID_EDIT_FIND)
		self.HookCommand(self.OnCmdEditRepeat, win32ui.ID_EDIT_REPEAT)
		self.HookCommand(self.OnCmdEditReplace, win32ui.ID_EDIT_REPLACE)
		self.HookCommand(self.OnCmdGotoLine, win32ui.ID_EDIT_GOTO_LINE)
		self.HookCommand(self.OnFilePrint, afxres.ID_FILE_PRINT)
		self.HookCommand(self.OnFilePrint, afxres.ID_FILE_PRINT_DIRECT)
		self.HookCommand(self.OnFilePrintPreview,
			win32ui.ID_FILE_PRINT_PREVIEW)
		# Key bindings.
		self.HookMessage(self.OnKeyDown, win32con.WM_KEYDOWN)
		self.HookMessage(self.OnKeyDown, win32con.WM_SYSKEYDOWN)
		# Hook wheeley mouse events
#		self.HookMessage(self.OnMouseWheel, win32con.WM_MOUSEWHEEL)
		self.HookFormatter() 
Example #8
Source File: winpty.py    From marsnake with GNU General Public License v3.0 5 votes vote down vote up
def sendkeypress(self, key):
        hwnd = self.Console_hwnd[0]

        # win32gui.PostMessage(hwnd, win32con.WM_KEYDOWN, key, 0)
        win32gui.PostMessage(hwnd, win32con.WM_KEYUP, key, 0) 
Example #9
Source File: winguiauto.py    From PyAutoTrading with GNU General Public License v2.0 5 votes vote down vote up
def pressKey(hwnd, key_code):
    '''
    模拟按键
    :param hwnd: 窗体句柄
    :param key_code: 按键码,在win32con下,比如win32con.VK_F1
    :return:
    '''
    win32gui.PostMessage(hwnd, win32con.WM_KEYDOWN, key_code, 0)  # 消息键盘
    time.sleep(.2)
    win32gui.PostMessage(hwnd, win32con.WM_KEYUP, key_code, 0)
    time.sleep(.2) 
Example #10
Source File: winguiauto.py    From pyautotrade_tdx with GNU General Public License v2.0 5 votes vote down vote up
def sendKey(hwnd, key_code):
    '''
    模拟按键
    :param hwnd: 窗体句柄
    :param key_code: 按键码,在win32con下,比如win32con.VK_F1
    :return:
    '''
    win32gui.PostMessage(hwnd, win32con.WM_KEYDOWN, key_code, 0)  # 消息键盘
    time.sleep(.2)
    win32gui.PostMessage(hwnd, win32con.WM_KEYUP, key_code, 0) 
Example #11
Source File: winguiauto.py    From pyAutoTrading with GNU General Public License v2.0 5 votes vote down vote up
def sendKeyMsg(hwnd, key_code):
    """
    模拟按键
    :param hwnd: 窗体句柄
    :param key_code: 按键码,在win32con下,比如win32con.VK_F1
    :return:
    """
    win32gui.PostMessage(hwnd, win32con.WM_KEYDOWN, key_code, 0)  # 消息键盘
    time.sleep(0.2)
    win32gui.PostMessage(hwnd, win32con.WM_KEYUP, key_code, 0)
    time.sleep(0.2) 
Example #12
Source File: winguiauto.py    From pyautotrade_tdx with GNU General Public License v2.0 4 votes vote down vote up
def sendKey(hwnd, key_code):
    '''
    模拟按键
    :param hwnd: 窗体句柄
    :param key_code: 按键码,在win32con下,比如win32con.VK_F1
    :return:
    '''
    win32gui.PostMessage(hwnd, win32con.WM_KEYDOWN, key_code, 0)  # 消息键盘
    time.sleep(.2)
    win32gui.PostMessage(hwnd, win32con.WM_KEYUP, key_code, 0)