https://heodolf.tistory.com/61
from pynput.keyboard import Listener, Key, KeyCode
import win32api,pyautogui,pyperclip
store = set()
HOT_KEYS = {
'print_hello': set([ Key.alt_l, KeyCode(char='1')] )
, 'open_notepad': set([ Key.alt_l, KeyCode(char='2')] )
}
def print_hello():
pyperclip.copy("안녕하세요")
pyautogui.hotkey('ctrl','v')
def open_notepad():
print('open_notepad')
try:
win32api.WinExec('notepad.exe')
except Exception as err:
print( err )
def handleKeyPress( key, **kwargs ):
store.add( key )
def handleKeyRelease( key ):
for action, trigger in HOT_KEYS.items():
CHECK = all([ True if triggerKey in store else False for triggerKey in trigger ])
if CHECK:
try:
action = eval( action )
if callable( action ):
action()
except NameError as err:
print( err )
# 종료
if key == Key.esc:
return False
elif key in store:
store.remove( key )
with Listener(on_press=handleKeyPress, on_release=handleKeyRelease) as listener:
listener.join()
'프로그래밍언어 > Python' 카테고리의 다른 글
Python Exe빌드 (0) | 2022.12.03 |
---|---|
구글번역 api (0) | 2022.07.23 |
키 입력확인하기 (0) | 2021.04.16 |
파이썬 exe만들기 (0) | 2020.12.11 |
파이썬 엑셀 (0) | 2020.12.05 |