Python win32con.VK_CONTROL Examples

The following are 7 code examples of win32con.VK_CONTROL(). 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: inputs.py    From NGU-scripts with GNU Lesser General Public License v3.0 7 votes vote down vote up
def click_drag(x :int, y :int, x2 :int, y2 :int) -> None:
        """Click at pixel xy."""
        x += Window.x
        y += Window.y
        x2 += Window.x
        y2 += Window.y
        lParam = win32api.MAKELONG(x, y)
        lParam2 = win32api.MAKELONG(x2, y2)
        # MOUSEMOVE event is required for game to register clicks correctly
        win32gui.PostMessage(Window.id, wcon.WM_MOUSEMOVE, 0, lParam)
        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_LBUTTONDOWN,
                             wcon.MK_LBUTTON, lParam)
        time.sleep(userset.LONG_SLEEP * 2)
        win32gui.PostMessage(Window.id, wcon.WM_MOUSEMOVE, 0, lParam2)
        time.sleep(userset.SHORT_SLEEP)
        win32gui.PostMessage(Window.id, wcon.WM_LBUTTONUP,
                             wcon.MK_LBUTTON, lParam2)
        time.sleep(userset.MEDIUM_SLEEP) 
Example #3
Source File: editor.py    From ironpython2 with Apache License 2.0 6 votes vote down vote up
def OnKeyDown(self, msg):
		key = msg[2]
		if win32api.GetKeyState(win32con.VK_CONTROL) & 0x8000:
			modList = MODIFYING_VK_KEYS_CTRL
		elif win32api.GetKeyState(win32con.VK_MENU) & 0x8000:
			modList = MODIFYING_VK_KEYS_ALT
		else:
			modList = MODIFYING_VK_KEYS

		if key in modList:
			# Return 1 if we can make the file editable.(or it already is!)
			return self.GetDocument().CheckMakeDocumentWritable()
		return 1 # Pass it on OK

#	def OnKey(self, key):
#		return self.GetDocument().CheckMakeDocumentWritable() 
Example #4
Source File: win32_window.py    From dragonfly with GNU Lesser General Public License v3.0 6 votes vote down vote up
def set_foreground(self):
        # Bring this window into the foreground if it isn't already the
        # current foreground window.
        if self.handle != win32gui.GetForegroundWindow():
            if self.is_minimized:
                self.restore()

            # Press a key so Windows allows us to use SetForegroundWindow()
            # (received last input event). See Microsoft's documentation on
            # SetForegroundWindow() for why this works.
            # Only do this if neither the left or right control keys are
            # held down.
            if win32api.GetKeyState(win32con.VK_CONTROL) == 0:
                Key("control:down,control:up").execute()

            # Set the foreground window.
            self._set_foreground() 
Example #5
Source File: inputs.py    From NGU-scripts with GNU Lesser General Public License v3.0 5 votes vote down vote up
def click(x :int, y :int, button :str ="left", fast :bool =False) -> None:
        """Click at pixel xy."""
        x += Window.x
        y += Window.y
        lParam = win32api.MAKELONG(x, y)
        # MOUSEMOVE event is required for game to register clicks correctly
        win32gui.PostMessage(Window.id, wcon.WM_MOUSEMOVE, 0, lParam)
        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)
        if button == "left":
            win32gui.PostMessage(Window.id, wcon.WM_LBUTTONDOWN,
                                 wcon.MK_LBUTTON, lParam)
            win32gui.PostMessage(Window.id, wcon.WM_LBUTTONUP,
                                 wcon.MK_LBUTTON, lParam)
        else:
            win32gui.PostMessage(Window.id, wcon.WM_RBUTTONDOWN,
                                 wcon.MK_RBUTTON, lParam)
            win32gui.PostMessage(Window.id, wcon.WM_RBUTTONUP,
                                 wcon.MK_RBUTTON, lParam)
        # Sleep lower than 0.1 might cause issues when clicking in succession
        if fast:
            time.sleep(userset.FAST_SLEEP)
        else:
            time.sleep(userset.MEDIUM_SLEEP) 
Example #6
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 #7
Source File: bindings.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
def fire_key_event(self, msg):
		key = msg[2]
		keyState = 0
		if win32api.GetKeyState(win32con.VK_CONTROL) & 0x8000:
			keyState = keyState | win32con.RIGHT_CTRL_PRESSED | win32con.LEFT_CTRL_PRESSED
		if win32api.GetKeyState(win32con.VK_SHIFT) & 0x8000:
			keyState = keyState | win32con.SHIFT_PRESSED
		if win32api.GetKeyState(win32con.VK_MENU) & 0x8000:
			keyState = keyState | win32con.LEFT_ALT_PRESSED | win32con.RIGHT_ALT_PRESSED
		keyinfo = key, keyState
		# Special hacks for the dead-char key on non-US keyboards.
		# (XXX - which do not work :-(
		event = self.keymap.get( keyinfo )
		if event is None:
##			if key == 220: # Dead key
##				return 1
##			# Translate the raw scancode into an Ascii character.
##			print "translating", key, "(with state)", keyState,
##			key = win32ui.TranslateVirtualKey(key)
##			print "Got back key", `key`,
####			if key is None:
####				return 1 # Dead-key - don't handle at all!!!
##			if key:
##				# Then back to a "normalized" scan-code.
##				key = keycodes.get_scan_code(key[0])
##				keyinfo = key, keyState
##				event = self.keymap.get( keyinfo )
##			if event is None:
				return 1
		return self.fire(event, None)