'Alt_L key release function does not start
I'm trying to implement ALT + TAB behavior.
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
if _M.preview_wbox.visible then
_M.preview_wbox.visible = false
else
_M.previewDelayTimer:stop()
end
if key == "Escape" then
-- Cancel client selection
for i = 1, #_M.altTabTable do
_M.altTabTable[i].client.opacity = _M.altTabTable[i].opacity
_M.altTabTable[i].client.minimized = _M.altTabTable[i].minimized
end
else
-- Raise clients in order to restore history
local c
for i = 1, _M.altTabIndex - 1 do
c = _M.altTabTable[_M.altTabIndex - i].client
if not _M.altTabTable[i].minimized then
c:raise()
client.focus = c
end
end
-- raise chosen client on top of all
c = _M.altTabTable[_M.altTabIndex].client
c:raise()
client.focus = c
-- restore minimized clients
for i = 1, #_M.altTabTable do
if i ~= _M.altTabIndex and _M.altTabTable[i].minimized then
_M.altTabTable[i].client.minimized = true
end
_M.altTabTable[i].client.opacity = _M.altTabTable[i].opacity
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.
Solution 1:[1]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Uli Schlachter |
