 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
a_h_k
Joined: 02 Feb 2008 Posts: 626
|
Posted: Sun Mar 14, 2010 2:55 am Post subject: Help Selector |
|
|
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 |
Last edited by a_h_k on Mon Apr 26, 2010 7:01 am; edited 2 times in total |
|
| Back to top |
|
 |
Morpheus
Joined: 31 Jul 2008 Posts: 273
|
Posted: Sun Mar 14, 2010 2:20 pm Post subject: |
|
|
Nice idea.
I thought you might be interested in knowing that you don't have to create, and then destroy your GUI everytime.
| Code: | /*------------------------------------------------------------------------
Author: a_h_k
Last updated: 14 Mar 2010
USAGE:
F1 = invokes Gui
F1 / Tab = moves (right) through the buttons
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
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
; Create Gui
Gui, -MaximizeBox -MinimizeBox ; -SysMenu
Gui, Add, Button, x1 y1 w130 h30 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, Hide w527 h32, %Gui_Title%
dPressDel = -400 ;must be -
$F1::
IfWinExist, %Gui_Window%
{
IfWinActive, %Gui_Window%
{ ; Now F1 will have DIFFERENT functions!
If (not done_1st_press)
{ ; This press = 1st
SetTimer, Tab, %dPressDel% ;if press F1 again WITHIN this period, then will NOT send Tab (but will "double-click" button)
done_1st_press = 1
}
Else
{ ; Done_1st_press + Timer started .. now at 2nd press (ie BEFORE timer elapsed)
;If done_1st_press = 1 (still), then Tab routine hasn't run, :. timer not yet elapsed
SetTimer, Tab, Off ;Cancel/abort the timer/Tab (as 1st press = instead now is 1st part of "double-click")
Send {Space} ;like mouse double-click
}
}
Else
{
WinActivate, %Gui_Window% ;bring to front
done_1st_press = 0
}
}
Else
{
Gui, Show
done_1st_press = 0
}
Return
#IfWinActive, ahk_group Gui_Window ;as "#IfWinActive, %Gui_Window%" is illegal
Esc::Gui, Hide
Enter::Send {Space}
GuiClose:
Gui, Hide
Return
Autohotkey:
Gui, Hide
RunOrActivate(HelpPath, "hh.exe", "AutoHotkey Help ahk_class HH Parent")
Return
Application:
Gui, Hide
Send {F1}
Return
Windows:
Gui, Hide
Send {F1}
Return
Cancel:
Gui, Hide
Return
Tab:
done_1st_press = 0
Send {Tab}
Return |
|
|
| Back to top |
|
 |
a_h_k
Joined: 02 Feb 2008 Posts: 626
|
Posted: Sat Mar 20, 2010 11:10 am Post subject: |
|
|
Thanks for that idea, but it really isn't necessary!
As:
- Script works fine as-is (this doesn't make it go "faster" or anything)
- The "Gui, Show" displays the window with the previous button selected (i think it's better to always have button #1 selected when invoke window)
- Your way displays the window when first load the script (but only want to display window when press F1) |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|