Python - Hot Keys - Run Code With Keyboard Key Press

preview_player
Показать описание
In Python we take a look on creating hotkeys inside python to run your code when you need by just using your hand on a key

CODE:
Рекомендации по теме
Комментарии
Автор

Hi, Tab Nation, your script is very useful; however, you have not explained to make the 'execute' function to do different things with different combination of keys, could you please make another video to explain this

purushothamaraju
Автор

can you use this code at any time? eg if vscode or pycharm or the .py file is not loaded. cuz I'm making a YouTube video/audio downloader and I need to know. thx

doober.
Автор

can you show one where you can toggle a loop code on and off by pressing the same button

capro
Автор

Hrm, interesting.

if I hit SHIFT, nothing happens. SHIFT+A then it runs, but after 5 seconds if I just hit SHIFT it also runs the code.

frontdesk
Автор

when I press A it executes program and types A, cant figure out how to make it execute code without typing a hotkey, for example, pressing F1 as a hotkey without trigering "help" feature on a web

password
Автор

this is 100X better way to do this thing, you're welcome

import keyboard

def f1_Pressed():
print('F1 was pressed')


def f2_Pressed():
print('F2 was pressed')

keyboard.remap_hotkey("F1", "F8")
keyboard.add_hotkey('F1', f1_Pressed)

keyboard.remap_hotkey("F2", "F8")
keyboard.add_hotkey('F2', f2_Pressed)

while True:
keyboard.wait()

password