将某些功能键 (FN) 绑定到 AwesomeWM 会破坏它们,直到取消绑定

将某些功能键 (FN) 绑定到 AwesomeWM 会破坏它们,直到取消绑定

用一个戴尔灵越 15 7580。很棒的是4.3版本

我使用 检查我的密钥的名称xev。按音量键会返回通常的结果。

KeyPress event, serial 36, synthetic NO, window 0x1200001,
    root 0x169, subw 0x1200002, time 13968342, (38,56), root:(841,97),
    state 0x0, keycode 122 (keysym 0x1008ff11, XF86AudioLowerVolume), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 0 bytes:
    XFilterEvent returns: False

KeyRelease event, serial 36, synthetic NO, window 0x1200001,
    root 0x169, subw 0x1200002, time 13968484, (38,56), root:(841,97),
    state 0x0, keycode 122 (keysym 0x1008ff11, XF86AudioLowerVolume), same_screen YES,
    XLookupString gives 0 bytes:
    XFilterEvent returns: False

所以我将密钥绑定到AwesomeWM...

awful.key({ }, "XF86AudioLowerVolume", 
    awful.spawn("amixer set Master 5%-"), {})

但是一旦我刷新 Awesome,绑定就不起作用并xev返回不同的结果

FocusOut event, serial 36, synthetic NO, window 0x1800001,
    mode NotifyGrab, detail NotifyAncestor

FocusIn event, serial 36, synthetic NO, window 0x1800001,
    mode NotifyUngrab, detail NotifyAncestor

KeymapNotify event, serial 36, synthetic NO, window 0x0,
    keys:  105 0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
           0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0

解除绑定后,功能键又可以使用了。但为什么会出现这种情况呢?一旦我绑定了它,它甚至不是我的音量键。

答案1

我想到了。由于某种原因,我不得不awful.spawn在匿名函数内部使用。我想既然awful.spawn是一个函数,我就不必这样做。但不幸的是,你确实这么做了。

awful.key({ }, "XF86AudioLowerVolume", function() 
    awful.spawn("amixer set Master 5%-") 
end, 
{description = "lower audio", group = "audio"}),

编辑我想我会解释一下。

因此( metatable for )press的参数需要 a作为参数。key.new__callawful.keyfunctionawful.spawn 类型function,但它返回什么不是一个函数。因此,在这种情况下,只能将函数作为参数传递,而不能调用该函数。

好例子

-- Notice I passed awful.spawn without calling it
awful.key({ }, "t", awful.spawn, {})

坏榜样

-- awful.spawn is called here, so whats returned by it is passed as an argument
awful.key({ }, "t", awful.spawn(), {})

请记住,您始终可以通过调用来检查 lua 中的类型type

type(awful.spawn)
function

相关内容