I originally started this due to the annoyance of Windows Help being loaded when i didn't want it to be (accidently pressing F1 (eg "aiming" for F2), or not realizing i wasn't still in app's window when pressed F1, and also for the convenience of a single hotkey to load Autohotkey help (which i use a lot)
Code:
/*
------------------------------------------------------------------------
Author: a_h_k
Last updated: 26 Mar 2010
USAGE:
F1 = invokes Gui
F1 / Tab = moves (right) through the buttons
1/2/3/4 = selects an option (left --> right)
F1x2 / Space / Enter / LMB = selects button
Esc = exits
F1x2 is a "double-press". The delay between presses is set via dPressDel
------------------------------------------------------------------------
*/
#NoTrayIcon
#SingleInstance, Force
SetTitleMatchMode, 3
SendMode, Input
HelpPath = %A_AhkPath%\AutoHotkey.chm
Gui_Title = Help Selector --- Please choose ---
Gui_Class = ahk_class AutoHotkeyGUI
Gui_Window = %Gui_Title% %Gui_Class%
GroupAdd, Gui_Window, %Gui_Window% ;for #IfWinActive
dPressDel = -400 ;must be -
$F1::
;Check for EXISTENCE of HelpSelector window
;
IfWinNotExist, %Gui_Window%
{ ; Create Gui
Gui, -MaximizeBox -MinimizeBox ; -SysMenu
Gui, Add, Button, x1 y1 w130 h30 Default gAutohotkey, Autohotkey
Gui, Add, Button, x130 y1 w130 h30 gApplication, Application
Gui, Add, Button, x260 y1 w130 h30 gWindows, Windows
Gui, Add, Button, x396 y1 w130 h30 gCancel, Cancel
Gui, Show, w527 h32, %Gui_Title%
return
}
;HelpSelector window exists
;Check for ACTIVE status of HelpSelector window
;
IfWinNotActive, %Gui_Window%
{
WinActivate, %Gui_Window% ;bring to front
return
}
;HelpSelector window exists AND is active/up
;Now handle the user selection(s)
; (Now F1 will have 2 DIFFERENT possible functions!)
KeyWait, F1 ;for GetKeyState()
; Wait to see what will happen (with F1)
;
done_timer = 0
SetTimer, CheckDoubleF1, %dPressDel% ;if press F1 again WITHIN this period, then will RE-TRIGGER $F1 hotkey
Loop
{
If (done_timer or GetKeyState("F1","P"))
{
SetTimer, CheckDoubleF1, Off ;Cancel/abort the timer/Tab (as 1st press = instead now is 1st part of "double-click")
Break
}
Sleep 10 ; --> "DOUBLE-CLICK" button (instead of Tab)
}
If (done_timer)
{
Send {Tab}
}
Else ;F1 presses again (within timer period)
{
Send {Space down} ;Like mouse double-click
Sleep, 500 ;Show button being pressed for a moment (before destroying gui)
Send {Space up}
}
Return
#IfWinActive, ahk_group Gui_Window ;as "#IfWinActive, %Gui_Window%" is illegal
Esc::Gui, Destroy
Enter::Send {Space}
1::
ControlClick, Button1, ahk_group Gui_Window,,,,D
Sleep, 500 ;Show button being pressed for a moment (before destroying gui)
ControlClick, Button1, ahk_group Gui_Window,,,,U
Gosub Autohotkey
Return
2::
ControlClick, Button2, ahk_group Gui_Window,,,,D
Sleep, 500 ;Show button being pressed for a moment (before destroying gui)
ControlClick, Button2, ahk_group Gui_Window,,,,U
Gosub Application
Return
3::
ControlClick, Button3, ahk_group Gui_Window,,,,D
Sleep, 500 ;Show button being pressed for a moment (before destroying gui)
ControlClick, Button3, ahk_group Gui_Window,,,,U
Gosub Windows
Return
4::
ControlClick, Button4, ahk_group Gui_Window,,,,D
Sleep, 500 ;Show button being pressed for a moment (before destroying gui)
ControlClick, Button4, ahk_group Gui_Window,,,,U
Gosub Cancel
Return
GuiClose:
Gui, Destroy
Return
Autohotkey:
Gui, Destroy
RunOrActivate("D:\Program Files\AutoHotkey\AutoHotkey.chm", "hh.exe", "AutoHotkey Help ahk_class HH Parent") ;or A_AhkPath
Sleep, 1500
Send !n ;Go to Index tab
Sleep, 500
; Highlight current tab's text (if any), in readiness for entering new letters to search for
ControlSend, Edit1, {Home}, AutoHotkey Help ahk_class HH Parent
ControlSend, Edit1, {Shift Down}{End}{Shift Up}, AutoHotkey Help ahk_class HH Parent
Return
Application:
Gui, Destroy
Send {F1}
Return
Windows:
Gui, Destroy
Send {F1}
Return
Cancel:
Gui, Destroy
Return
CheckDoubleF1:
;If get here, then $F1:: hasn't been re-triggered --> :. HAVEN'T "double-clicked" F1
done_timer = 1
Return