grabbing keyboard doesnt allow changing focus

ⅰ亾dé卋堺 提交于 2019-12-07 15:55:24

问题


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.

i read something about grab_keyboard generating focusevents, but that doesnt mean it blocks all focus events, does it?

what am i not getting here?

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()

回答1:


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.



来源:https://stackoverflow.com/questions/18160990/grabbing-keyboard-doesnt-allow-changing-focus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!