Macro { area="Shell"; key="Alt"; description="Use Alt for search by name (activate)"; action = function() -- add feature: ignore Alt+Tab via task-switch/focus check local ok, ffi = pcall(require, "ffi") if not ok then far.Show(); return end pcall(ffi.cdef, [[ typedef void* HWND; HWND GetForegroundWindow(void); int GetClassNameA(HWND hWnd, char* lpClassName, int nMaxCount); ]]) local oku, user32 = pcall(ffi.load, "user32") if not oku then far.Show(); return end local function foreground_class() local hwnd = user32.GetForegroundWindow() if hwnd == nil or hwnd == ffi.NULL then return "" end local buf = ffi.new("char[256]") if user32.GetClassNameA(hwnd, buf, 256) == 0 then return "" end return ffi.string(buf) end local function foreign_focus() local class = foreground_class() if class == "" then return false end -- Classic Alt+Tab switcher dialog if class == "#32770" then return true end -- Our own console/terminal hosts (conhost, Windows Terminal, etc.) if class=="CASCADIA_HOSTING_WINDOW_CLASS" or class=="ConsoleWindowClass" then return false end -- Foreign window got focus => Alt+Tab completed (or something stole focus) return true end if foreign_focus() then return end -- Give Windows a moment to finish the Alt+Tab focus switch, then re-check mf.sleep(40) if foreign_focus() then return end if APanel.Visible then Keys('Alt<') else if Object.Selected then Keys('CtrlU') else Keys('SelWord') end end end; }