コード例 #1
0
ファイル: SendKey.py プロジェクト: olve/Bristow
def send_key_to_windows_with_title(key, regex, send_to_children=False):
	windows = WindowsTools.enum_windows(regex)
	for HWND in windows:
		_send_key(key, HWND)
		if send_to_children:
			child_windows = WindowsTools.enum_child_windows(window)
			for window in child_windows:
				_send_key(key, window)
コード例 #2
0
ファイル: SendKey.py プロジェクト: olve/Bristow
def send_key_to_windows_with_title(key, regex, send_to_children=False):
	"""Send a simulated keypress to all windows with titles matching a regular expression

	Keyword arguments:
	key -- ID of the key you want to send (decimal)
	regex -- The regular expression to search with
	send_to_children -- if True, the keypress will be sent to all child-windows of the parent

	"""
	windows = WindowsTools.enum_windows(regex)
	for HWND in windows:
		_send_key(key, HWND)
		if send_to_children:
			child_windows = WindowsTools.enum_child_windows(window)
			for window in child_windows:
				_send_key(key, window)
コード例 #3
0
ファイル: SendKey.py プロジェクト: olve/Bristow
def send_key(key, HWND, send_to_children=False):
	"""Send a simulated keypress to a window.

	Keyword arguments:
	key -- ID of the key you want to send (decimal)
	HWND -- The window handle of the target window
	send_to_children -- if True, the keypress will be sent to all child-windows of the parent

	"""
	_send_key(key, HWND)
	if send_to_children:
		child_windows = WindowsTools.enum_child_windows(HWND)
		for window in child_windows:
			_send_key(key, window)
コード例 #4
0
ファイル: SendKey.py プロジェクト: olve/Bristow
def send_key(key, HWND, send_to_children=False):
	"""Send a simulated keypress to a window.

	Keyword arguments:
	key -- The Key ID (examples: "Space", "Numpad0", "B")
	HWND -- The window handle of the target window
	send_to_children -- if True, the keypress will be sent to all child-windows of the parent

	"""
	_send_key(key, HWND)
	if send_to_children:
		child_windows = WindowsTools.enum_child_windows(HWND)
		for window in child_windows:
			_send_key(key, window)
コード例 #5
0
ファイル: SpotifyControls.py プロジェクト: olve/Bristow
def restart_spotify(spotify_exe_path):
	"""Terminates and restarts spotify"""
	spotify_hwnd = get_spotify_instance()._hwnd
	WindowsTools.kill_process_by_HWND(spotify_hwnd)
	WindowsTools.create_process(spotify_exe_path, creation_flags=WindowsTools.Defines.CREATE_NEW_CONSOLE)
コード例 #6
0
ファイル: main.py プロジェクト: olve/Bristow
    if arguments is not None:
        thread = threading.Thread(target=function, args=arguments)
    else:
        thread = threading.Thread(target=function)
    thread.start()


# Hook Spotify and start controller
spotify_hook = SpotifyControls.SpotifyHook()
create_thread(spotify_hook.start_hook)

# Keybindings for KeyboardHook
# Keybinding-format: "key-name":lambda : instruction(arg1, arg2)
keybindings = {
    "Numpad1": lambda: spotify_hook.controller.previous_track(),
    "Numpad3": lambda: spotify_hook.controller.next_track(),
    "Multiply": lambda: spotify_hook.controller.playpause(),
    "Add": lambda: spotify_hook.controller.volume_up(),
    "Subtract": lambda: spotify_hook.controller.volume_down(),
    "Numpad0": lambda: WindowsTools.SendKey.send_key_to_windows_with_title(32, regex="VLC media player"),
    "Decimal": lambda: WindowsTools.SendKey.send_key_to_windows_with_title(70, regex="VLC media player"),
    # "Numpad4":lambda : WindowsFunctions.kill_window_process(regex="Fallout3"),
    "Numpad7": lambda: WindowsTools.kill_process_by_HWND(WindowsTools.get_foreground_window()),
    "Numpad8": lambda: SpotifyControls.restart_spotify("C:/Users/xqo/AppData/Roaming/Spotify/spotify.exe"),
    # "Numpad5":lambda : ChromeFunctions.playpause_youtube(),
    # "Numpad5":lambda : LoadExe.load("calc.exe"),
}

# Hook keyboard
create_thread(KeyboardHook.bind_keys, arguments=(keybindings,))