alt+ TAB行为实现

发布于 2025-01-20 08:55:20 字数 2161 浏览 0 评论 0原文

我正在尝试实现 ALT + TAB 行为。
我想知道用户何时按住 ALT 键。

为什么这个释放功能不起作用?

awful.key(
{}, 
'Alt_L',
function()
   altHold = true
end,
function()
   altHold = false
end 
),

不切实际的解决方案:

awful.key(
{}, 
'Alt_L',
function()
   altHold = true
end 
),  
awful.key(
{'Mod1'},
'Alt_L',
nil,
function()
   altHold = false
end 
)

这可行,但任何其他带 ALT 的热键都不再起作用。

其他解决方案:

    keygrabber.run(
        function (mod, key, event)
            -- Stop alt-tabbing when the alt-key is released
            if gears.table.hasitem(mod, "Mod1") then
                if (key == "Alt_L" or key == "Escape") and event == "release" then
                    -- Make it visible

                    if key == "Escape" then
                        -- Cancel client selection
                        end
                    else
                        -- Raise clients in order to restore history

                        -- raise chosen client on top of all

                        -- restore minimized clients
                        end
                    end

                    keygrabber.stop()
                
                -- Pressed tab
                elseif key == "Tab" and event == "press" then
                    if gears.table.hasitem(mod, "Shift") then
                        -- Move to previous client on Shift-Tab
                        cyclePreview(-1)
                    else
                        -- Move to next client on each Tab-press
                        cyclePreview( 1)
                    end
                end
            end
        end
    )

这是 Troglobit 的稍微修改版本:
https://github.com/troglobit/ Awesome-switcher/blob/master/init.lua#L470-L525\
按下 ALT + TAB 时会调用此函数。
按住 ALT 的同时,按下一个 TAB 键将调用 previewCycle() 函数。
如果 ALT 被释放,它将选择所选的客户端。
ESCAPE 取消选择。

I'm trying to implement ALT + TAB behaviour.
I want to know when a user is holding the ALT key.

Why does this release function not work?

awful.key(
{}, 
'Alt_L',
function()
   altHold = true
end,
function()
   altHold = false
end 
),

IMPRACTICAL SOLUTION:

awful.key(
{}, 
'Alt_L',
function()
   altHold = true
end 
),  
awful.key(
{'Mod1'},
'Alt_L',
nil,
function()
   altHold = false
end 
)

This works, but any other hotkeys with ALT no longer work.

OTHER SOLUTION:

    keygrabber.run(
        function (mod, key, event)
            -- Stop alt-tabbing when the alt-key is released
            if gears.table.hasitem(mod, "Mod1") then
                if (key == "Alt_L" or key == "Escape") and event == "release" then
                    -- Make it visible

                    if key == "Escape" then
                        -- Cancel client selection
                        end
                    else
                        -- Raise clients in order to restore history

                        -- raise chosen client on top of all

                        -- restore minimized clients
                        end
                    end

                    keygrabber.stop()
                
                -- Pressed tab
                elseif key == "Tab" and event == "press" then
                    if gears.table.hasitem(mod, "Shift") then
                        -- Move to previous client on Shift-Tab
                        cyclePreview(-1)
                    else
                        -- Move to next client on each Tab-press
                        cyclePreview( 1)
                    end
                end
            end
        end
    )

This is a slightly modified version from Troglobit:
https://github.com/troglobit/awesome-switcher/blob/master/init.lua#L470-L525\

This gets called when ALT + TAB is pressed.
While holding ALT, the next TAB press calls previewCycle() function.
If ALT is released it selects the chosen client.
ESCAPE cancels the selection.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

得不到的就毁灭 2025-01-27 08:55:20

随机猜测:释放键时,“ alt”修饰符处于活动状态,因此您需要一个用mod1作为修改器的键框(IS Alt mod1 我不确定)。但是,当然,这种键绑定将不会对钥匙按下反应,因此您需要两个。

Random guess: When the key is released, the "alt" modifier is active, so you need a keybinding with Mod1 as modifier (is Alt Mod1? I'm not entirely sure). But of course, that key binding would then not react to key presses, so you need two.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文