IFWinActrive stop keyboard key from working out of the focused window

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kovace
Posts: 1
Joined: 14 Apr 2024, 15:43

IFWinActrive stop keyboard key from working out of the focused window

Post by kovace » 14 Apr 2024, 17:18

So I may not look hard enough but I m stuck. The script Is not important I think but I general this is the idea. I have a script who use let say F4 for do a task like search something in "window explorer" (.fbx) and change sorting view from name and bla bla. I put windows in focus I want to use F4 only in Window but normal in other program let say Photoshot (test in chrome and other program same). But AHK just disable the F4 and mean don't even fire the F4 in other program if Window E is not in focus. I remove the IFWinAcrtice but this play the script in other program. Now I try to change the script, read have something to do with privileges user so I put AHK in run as admin so PS to and nothing. Still as long the script is on and "If WinActive" is on the script the F4 don't work.
Here the script or at last part just to test

Code: Select all

#Persistent
#NoEnv

F4::  ; F4 Hotkey
    If WinActive("ahk_class CabinetWClass")
    {
        ; Active window is Windows Explorer
        Send, ^f  ; Send Ctrl+F to focus on the search bar
        Sleep, 500  ; Wait for search bar to focus
        Send, .fbx{Enter}  ; Search for .fbx files
        Sleep, 2000  ; Wait for search results
    }
    Else
    {
        ; Active window is not Windows Explorer
        Send, {Blind}{F4} ; Pass through the F4 key press as normal
    }
return


[Mod edit: Fixed misplaced bracket character in code tags. Code goes between the two tags, not inside the second tag.]

[Mod action: Topic moved from "Ask for Help (v2)" since this is v1 code.]
User avatar
mikeyww
Posts: 27011
Joined: 09 Sep 2014, 18:38

Re: IFWinActrive stop keyboard key from working out of the focused window

Post by mikeyww » 14 Apr 2024, 18:26

Welcome to this AutoHotkey forum!

An easy way is simply to use an #If directive before your hotkey. When the condition is not met, the hotkey does whatever it normally does.

Code: Select all

#Requires AutoHotkey v1.1.33.11

#If WinActive("ahk_class CabinetWClass")
F4::
MsgBox
Return
#If
A hotkey "sending itself" would typically use a $ prefix or #UseHook.

Explained: #If

If you are new to AHK, I recommend using its current version, which is v2, instead of this older deprecated version that is no longer developed.
Post Reply

Return to “Ask for Help (v1)”