How can i disable Alt+Tab combination, especially tab on my Tkinter App. I disabled Alt and F4 with - return "break" - but i can't disable Tab key with it.
Asked
Active
Viewed 2,351 times
0
-
you want the user to be locked out of using the `alt-tab` keyboard shortcut? That seems like an unnecessarily limiting feature, could you explain why you want to accomplish this? – Tadhg McDonald-Jensen Aug 23 '16 at 21:46
-
Also note that there are [lots of ways to switch between open apps](http://www.pcworld.com/article/238080/Windows.html) in windows so if your goal is to completely lock the user into your application you are out of luck. – Tadhg McDonald-Jensen Aug 23 '16 at 21:54
-
Because this is a screen lock. It locks up the screen, you enter the password, then open the screen. Logic of the program is like this. – Jakadar Aug 23 '16 at 22:26
-
I very much doubt it is possible to completely lock a user into a single application, and I believe that is intended by design. Why can't you [use the lock screen built into windows](http://stackoverflow.com/questions/20733441/lock-windows-workstation-using-python)? – Tadhg McDonald-Jensen Aug 23 '16 at 22:39
-
If you want to lock the screen, try doing a global grab. That will prevent anything other than your window from getting keypress events. While I haven't tried it, I suspect it will also grab alt-tab.About the only thing it won't grab are low-level interrupts like ctrl-alt-del. – Bryan Oakley Aug 23 '16 at 23:21
2 Answers
0
Tkinter provides no option for this. Alt-tab is intercepted before tkinter ever sees it. If you want to do this, you'll have to find some platform-specific hooks.

Bryan Oakley
- 370,779
- 53
- 539
- 685
0
import pyHook
import pygame
# create a keyboard hook
def OnKeyboardEvent(event):
if event.Key.lower() in ['tab','alt']#Keys to block:
return False # block these keys
else:
# return True to pass the event to other handlers
return True
# create a hook manager
hm = pyHook.HookManager()
# watch for all keyboard events
hm.KeyDown = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
# initialize pygame and start the game loop
pygame.init()
while(1):
pygame.event.pump()
To install pyhook First install pygame
pip install pygame
and pyhook from: this link:

Anonymous
- 596
- 1
- 9
- 26