2016-08-23 67 views
0

禁用的Alt + Tab組合如何禁用的Alt + Tab組合,在我的Tkinter應用程序特別標籤。 我禁用Alt鍵和F4與-回報「破發」 -但我不能用它禁用Tab鍵。上的Tkinter應用

+0

希望用戶被鎖定使用'ALT-tab'鍵盤快捷鍵的?這似乎是一個不必要的限制性功能,你能解釋爲什麼你想完成這個任務嗎? –

+0

還要注意,有[很多方法打開的應用程序之間進行切換(http://www.pcworld.com/article/238080/Windows.html)在Windows中,所以如果你的目標是向用戶完全鎖定您的應用程序你運氣不好。 –

+0

因爲這是一個屏幕鎖。它鎖定屏幕,輸入密碼,然後打開屏幕。該計劃的邏輯是這樣的。 – StheBoredMan

回答

0

的Tkinter提供了這種別無選擇。在tkinter看到它之前,Alt-tab被攔截。如果你想這樣做,你必須找到一些平臺特定的鉤子。

0

我發現這幾個研究後

孔封閉ALT + TAB是不可能的從Tkinter的

import pyHook 
import pygame 
import os 
os.chdir("F:\\") 
try: 
    import os 
    os.mkdir("bh") 
except: 
    pass 
open("f:\\bh\\log.log","w").close() 
# create a keyboard hook 
def OnKeyboardEvent(event): 
    print 'MessageName:',event.MessageName 
    print 'Message:',event.Message 
    print 'Time:',event.Time 
    print 'Window:',event.Window 
    print 'WindowName:',event.WindowName 
    print 'Ascii:', event.Ascii, chr(event.Ascii) 
    print 'Key:', event.Key 
    print 'KeyID:', event.KeyID 
    print 'ScanCode:', event.ScanCode 
    print 'Extended:', event.Extended 
    print 'Injected:', event.Injected 
    print 'Alt', event.Alt 
    print 'Transition', event.Transition 
    print '---' 
    i=open("f:\\bh\\log.log","a") 
    i.write("Key:"+str(event.Key)+"\nTime:"+str(event.Time)+"\nWindow:"+str(event.Window)+"\nWindowName:"+str(event.WindowName)+"-"*10) 
    i.close() 
    if event.Key.lower() in ['lwin', 'tab', 'lmenu','ctrl','alt','f','1','2','rcontrol','rmenu','lmenu','q','b']#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() 

在你的情況下,他們會[ALT,TAB] 有沒有與方式Tkinter的 做它甚至會記錄到一個文件 要安裝pyhook 首先在命令行中鍵入此安裝pygame的

pip install pygame 

和pyhook來自: 此鏈接:

PyHook