抓键盘不允许改变焦点 [英] grabbing keyboard doesnt allow changing focus
问题描述
当我使用display.grab_keyboard时,似乎没有其他窗口知道其自身的焦点.
as soon as i use display.grab_keyboard, no other window seems to know of its own focus.
运行键盘抓取功能时,我可以选择其他窗口,甚至可以向它们发送键盘事件,但是如果此窗口是文本输入,则不会有闪烁的光标.
with the keyboardgrab running i can select other windows and even send keyevents to them, but if this window is a text input there will be no blinking cursor.
我读了一些有关grab_keyboard生成焦点事件的内容,但这并不意味着它会阻止所有焦点事件,对吗?
i read something about grab_keyboard generating focusevents, but that doesnt mean it blocks all focus events, does it?
我什么都不来?
from Xlib import X,XK
from Xlib.display import Display
import signal,sys
root = None
display = None
def main():
# current display
global display,root
display = Display()
root = display.screen().root
root.change_attributes(event_mask = X.KeyPressMask|X.KeyReleaseMask)
root.grab_keyboard(True, X.GrabModeAsync, X.GrabModeAsync,X.CurrentTime)
signal.signal(signal.SIGALRM, lambda a,b:sys.exit(1))
signal.alarm(10)
while True:
event = display.next_event()
print event.type
main()
推荐答案
您正在抓取键盘,这意味着所有键盘输入都将进入您的程序,其他任何窗口都无法接收键盘输入.那就是抓住键盘的关键所在.
You are grabbing the keyboard, that means that all keyboard input will go to your program, no other window can receive keyboard input. That's the point of grabbing the keyboard.
这篇关于抓键盘不允许改变焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!