0
votes

CODE

currentstring := ""
q::
    ExitApp
return
w::
    MsgBox,,,Hello`, World!,3
return
e::
    MsgBox,,,Hello World,3
return
r::
    InputBox, currentstring
    *::
    return
return
t::
    MsgBox,,,%currentstring%,3
return

But when I am in the InputBox and I press q,w,e,r, or t, it executes the code before the return, even though I already override the hotkeys by *::.

Is there any fix to this?

1

1 Answers

0
votes

*:: is not a "catch all" hotkey, it just fires when it detects an asterisk (normally Shift+8).

To achieve your desired effect, you should activate the hotkeys based on the active window.

Working Example

If the active window is an InputBox (ahk_class #32270), disable the hotkeys, but don't block their native function (the ~ prefix). If not the InputBox, bind the hotkeys as desired.

#SingleInstance force
currentstring := ""
return ; end auto-execute section

#IfWinActive, ahk_class #32770 ; If an InputBox window, restore default key function
~q::
~w::
~e::
~r::
~t::
  return

#IfWinActive ; If anything else
q::
    ExitApp
return
w::
    MsgBox,,,Hello`, World!,3
return
e::
    MsgBox,,,Hello World,3
return
r::
    InputBox, currentstring
return
t::
    MsgBox,,,%currentstring%,3
return

Notes:

  • It is considered best practice to only bind the hotkeys you need, not to everything.
  • To determine a Window's properties (class, id, etc.), you can use the Active Window Info or Window Spy tool bundled with AutoHotKey. It can also be launched from the system tray icon of a running script if Menu, Tray, NoStandard has not been used.