Hello I'm trying to find a way to detect when the user press the alt+tab key combination.
What I want to do is next:
while True:
if not "alt+tab key pressed":
pythoncom.PumpMessages()
How can I do this?
Hello I'm trying to find a way to detect when the user press the alt+tab key combination.
What I want to do is next:
while True:
if not "alt+tab key pressed":
pythoncom.PumpMessages()
How can I do this?
in order to tackle this problem I've created this piece of code, I suggest using the time.sleep
function to slow down the input gathering as it can be quite resource intensive.
import time
import keyboard
alt_pressed = False
while True: # making an infinite loop
try:
if keyboard.is_pressed('alt'):
alt_pressed = True
print('You Pressed Alt')
if keyboard.is_pressed('tab') and alt_pressed:
print('You Pressed Alt+Tab')
break # finishing the loop
alt_pressed = False
time.sleep(0.05)
except:
break