代码之家  ›  专栏  ›  技术社区  ›  Chris Stryczynski

如何在xmonad中检测按键/按钮关闭事件?

  •  0
  • Chris Stryczynski  · 技术社区  · 5 年前

    我尝试通过以下方式手动检测:

    myHook :: Event -> X All
    myHook e = do
      liftIO $ logToTmpFile $ show e
      pure $ All True
    

    但是在按键上 modm ( hyper / windows )它只是显示:

    PropertyEvent {ev_event_type = 28, ev_serial = 12080, ev_send_event = False, ev_event_display = Display 0x0000000000df2340, ev_window = 27262982, ev_atom = 353, ev_time = 20662387, ev_propstate = 0}
    

    这看起来相当普通,不同的键似乎也会发出相同的事件。


    在检查xmonad源时,似乎“事件”只发生在要监听的“已注册”按键上。

    1 回复  |  直到 5 年前
        1
  •  0
  •   Chris Stryczynski    5 年前

    要注册“击键”,请执行以下操作:

    myStartupHook :: X ()
    myStartupHook = do
      XConf { display = dpy, theRoot = rootw } <- ask
      myKeyCode <- io $ (keysymToKeycode dpy xK_Super_R)
      io $ grabKey dpy (myKeyCode) anyModifier rootw True grabModeAsync grabModeAsync
    

    myHook :: Event -> X All
    myHook e = do
      liftIO $ logToTmpFile $ show e
      pure $ All True
    

    然后把这些加到你的 startupHook handleEventHook 配置中的值。

    我看到以下输出:

    KeyEvent {ev_event_type = 3, ev_serial = 2866, ev_send_event = False, ev_event_display = Display 0x0000000001217340, ev_window = 1056, ev_root = 1056, ev_subwindow = 25166105, ev_time = 4248223, ev_x = 1014, ev_y = 1038, ev_x_root = 1014, ev_y_root = 1038, ev_state = 64, ev_keycode = 134, ev_same_screen = True