list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script)

Put simple Tips and Tricks that are not entire Tutorials in this forum
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script)

06 Feb 2017, 10:16

I had noticed that certain AutoHotkey commands
had multiple WM_COMMAND IDs e.g. reload (65400 and 65303),
which was making it hard to maintain certain scripts.
So I decided to investigate and then choose a preferred
ID number where two were available.

==================================================

from AutoHotkey-master\Source\resources\resource.h (AutoHotkey v1.0.48.05 'AutoHotkey Basic' source code):
GitHub - AutoHotkey/AutoHotkey: AutoHotkey is a powerful and easy to use scripting language for desktop automation on Windows.
https://github.com/AutoHotkey/AutoHotkey

// Since WM_COMMAND IDs must be shared among all menus and controls, they are carefully conserved,
// especially since there are only 65,535 possible IDs. In addition, they are assigned to ranges
// to minimize the need that they will need to be changed in the future (changing the ID of a main
// menu item, tray menu item, or a user-defined menu item [by way of increasing MAX_CONTROLS_PER_GUI]
// is bad because some scripts might be using PostMessage/SendMessage to automate AutoHotkey itself).
// For this reason, the following ranges are reserved:
// 0: unused (possibly special in some contexts)
// 1: IDOK
// 2: IDCANCEL
// 3 to 1002: GUI window control IDs (these IDs must be unique only within their parent, not across all GUI windows)
// 1003 to 65299: User Defined Menu IDs
// 65300 to 65399: Standard tray menu items.
// 65400 to 65534: main menu items (might be best to leave 65535 unused in case it ever has special meaning)

IDs 65300-65307 and IDs 65400-65413:

ID_TRAY_OPEN := 65300
ID_FILE_RELOADSCRIPT := 65400 ;ID_TRAY_RELOADSCRIPT := 65303
ID_FILE_EDITSCRIPT := 65401 ;ID_TRAY_EDITSCRIPT := 65304
ID_FILE_WINDOWSPY := 65402 ;ID_TRAY_WINDOWSPY := 65302
ID_FILE_PAUSE := 65403 ;ID_TRAY_PAUSE := 65306
ID_FILE_SUSPEND := 65404 ;ID_TRAY_SUSPEND := 65305
ID_FILE_EXIT := 65405 ;ID_TRAY_EXIT := 65307
ID_VIEW_LINES := 65406
ID_VIEW_VARIABLES := 65407
ID_VIEW_HOTKEYS := 65408
ID_VIEW_KEYHISTORY := 65409
ID_VIEW_REFRESH := 65410
ID_HELP_USERMANUAL := 65411 ;ID_TRAY_HELP := 65301
ID_HELP_WEBSITE := 65412

==================================================

From:
Autohotkey-scripts-.ahk/AHKControl.ahk at master · Drugoy/Autohotkey-scripts-.ahk · GitHub
https://github.com/Drugoy/Autohotkey-sc ... ontrol.ahk

formerly at: autohotkey.net/~Lexikos/AHKControl/AHKControl.ahk

Cmd_Open = 65300
;-
Cmd_Reload = 65400
Cmd_Edit = 65401
Cmd_Pause = 65403
Cmd_Suspend = 65404
;-
Cmd_ViewLines = 65406
Cmd_ViewVariables = 65407
Cmd_ViewHotkeys = 65408
Cmd_ViewKeyHistory = 65409
;-
Cmd_Exit = 65405

missing from AHKControl.ahk list:
ID_FILE_WINDOWSPY := 65402 ;ID_TRAY_WINDOWSPY := 65302
ID_VIEW_REFRESH := 65410
ID_HELP_USERMANUAL := 65411 ;ID_TRAY_HELP := 65301
ID_HELP_WEBSITE := 65412

==================================================

Note: files inside source code zips/exes seem to differ:
GitHub - AutoHotkey/AutoHotkey: AutoHotkey is a powerful and easy to use scripting language for desktop automation on Windows.
https://github.com/AutoHotkey/AutoHotkey
Index of /download/1.0
https://autohotkey.com/download/1.0/

Note: the following opens the script with notepad.exe by default:
ID_FILE_EDITSCRIPT := 65401 ;ID_TRAY_EDITSCRIPT := 65304
this can be changed at:
HKEY_CLASSES_ROOT\AutoHotkeyScript\Shell\Edit\Command

Note: the following toggle rather than set pause/suspend modes:
ID_FILE_PAUSE := 65403 ;ID_TRAY_PAUSE := 65306
ID_FILE_SUSPEND := 65404 ;ID_TRAY_SUSPEND := 65305

==================================================

Usage example:

Code: Select all

q::
DetectHiddenWindows, On
SetTitleMatchMode, 2 ;A window's title can contain WinTitle anywhere
WinGet, hWnd, ID, \MyScript.ahk ahk_class AutoHotkey
PostMessage, 0x111, 65405,,, % "ahk_id " hWnd ;WM_COMMAND := 0x111 ;ID_FILE_EXIT := 65405
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script)

06 Jul 2017, 22:26

Code to choose alternative hotkeys for interacting with the main window, and to be able to interact with it while a MsgBox or other dialog is open.

program
https://autohotkey.com/docs/program.html
Known issue: Keyboard shortcuts for menu items do not work while the script is displaying a MsgBox or other dialog.

Code: Select all

;q::
DetectHiddenWindows, On
WinShow, % "ahk_id " A_ScriptHwnd
MsgBox
return

;list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script) - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=7&t=27824

#IfWinActive, ahk_class AutoHotkey
;WM_COMMAND := 0x111
;ID_TRAY_OPEN := 65300
^r::PostMessage, 0x111, 65400,,, A ;ID_FILE_RELOADSCRIPT := 65400 ;ID_TRAY_RELOADSCRIPT := 65303
^e::PostMessage, 0x111, 65401,,, A ;ID_FILE_EDITSCRIPT := 65401 ;ID_TRAY_EDITSCRIPT := 65304
;q::PostMessage, 0x111, 65402,,, A ;ID_FILE_WINDOWSPY := 65402 ;ID_TRAY_WINDOWSPY := 65302
Pause::PostMessage, 0x111, 65403,,, A  ;ID_FILE_PAUSE := 65403 ;ID_TRAY_PAUSE := 65306
;q::PostMessage, 0x111, 65404,,, A ;ID_FILE_SUSPEND := 65404 ;ID_TRAY_SUSPEND := 65305
;q::PostMessage, 0x111, 65405,,, A ;ID_FILE_EXIT := 65405 ;ID_TRAY_EXIT := 65307
^l::PostMessage, 0x111, 65406,,, A ;ID_VIEW_LINES := 65406
^v::PostMessage, 0x111, 65407,,, A ;ID_VIEW_VARIABLES := 65407
^h::PostMessage, 0x111, 65408,,, A ;ID_VIEW_HOTKEYS := 65408
^k::PostMessage, 0x111, 65409,,, A ;ID_VIEW_KEYHISTORY := 65409
F5::PostMessage, 0x111, 65410,,, A ;ID_VIEW_REFRESH := 65410
F1::PostMessage, 0x111, 65411,,, A ;ID_HELP_USERMANUAL := 65411 ;ID_TRAY_HELP := 65301
;q::PostMessage, 0x111, 65412,,, A ;ID_HELP_WEBSITE := 65412
#IfWinActive
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script)

07 Jul 2017, 03:24

This might be a handy shortcut. Thanks. :thumbup:
If I recall correctly, the suspend message toggles the suspension, do you know if there is a way to set the suspension state to either on or off?

Finally, this might be considered related, if not, you might be interested anyways,

cheers!
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script)

07 Jul 2017, 04:39

To set the Suspend state to on/off, I'd get the state and either toggle or not as appropriate, see the script below. Suspend has On/Off parameters it turns out, I don't really use it that much.

Thanks for the link, if there's a specific detail you had in mind, please say so. Cheers.

Well, to make a versatile script that could suspend itself and/or others, was slightly more involved than the one-liners above, but thanks for the idea. I've made it about as simple as I can, any improvements/suggestions are welcome.

When I wrote the small script above, I didn't realise that: inside every small script there's a big script trying to get out.

Code: Select all

#IfWinActive, ahk_group WinGroupThisScript
q:: ;autohotkey itself - suspend script
Suspend
ToolTip, % "Suspend set to: " (A_IsSuspended?"ON":"OFF")
Sleep 1000
ToolTip
return
#IfWinActive

#IfWinActive, ahk_class AutoHotkey
q:: ;autohotkey itself - suspend script
WinGet, hWnd, ID, A
if (hWnd = A_ScriptHwnd)
{
	GroupAdd, WinGroupThisScript, % "ahk_id " A_ScriptHwnd
	vIsSuspended := !A_IsSuspended
	Suspend
}
else
{
	vIsSuspended := !JEE_AhkWinIsSuspended(hWnd)
	PostMessage, 0x111, 65404,,, A ;ID_FILE_SUSPEND := 65404 ;ID_TRAY_SUSPEND := 65305
}
ToolTip, % "Suspend set to: " (vIsSuspended?"ON":"OFF")
Sleep 1000
ToolTip
return
#IfWinActive

;==================================================

;JEE_ScriptIsSuspended
JEE_AhkWinIsSuspended(hWnd)
{
	vDHW := A_DetectHiddenWindows
	DetectHiddenWindows, On
	SendMessage, 0x211,,,, % "ahk_id " hWnd ;WM_ENTERMENULOOP := 0x211
	SendMessage, 0x212,,,, % "ahk_id " hWnd ;WM_EXITMENULOOP := 0x212
	hMenuBar := DllCall("GetMenu", Ptr,hWnd, Ptr)
	hMenuFile := DllCall("GetSubMenu", Ptr,hMenuBar, Int,0, Ptr)
	;ID_FILE_SUSPEND := 65404
	vState := DllCall("GetMenuState", Ptr,hMenuFile, UInt,65404, UInt,0, UInt)
	vIsSuspended := (vState >> 3) & 1
	DetectHiddenWindows, % vDHW
	return vIsSuspended
}

;==================================================

;JEE_ScriptIsPaused
JEE_AhkWinIsPaused(hWnd)
{
	vDHW := A_DetectHiddenWindows
	DetectHiddenWindows, On
	SendMessage, 0x211,,,, % "ahk_id " hWnd ;WM_ENTERMENULOOP := 0x211
	SendMessage, 0x212,,,, % "ahk_id " hWnd ;WM_EXITMENULOOP := 0x212
	hMenuBar := DllCall("GetMenu", Ptr,hWnd, Ptr)
	hMenuFile := DllCall("GetSubMenu", Ptr,hMenuBar, Int,0, Ptr)
	;ID_FILE_PAUSE := 65403
	vState := DllCall("GetMenuState", Ptr,hMenuFile, UInt,65403, UInt,0, UInt)
	vIsPaused := (vState >> 3) & 1
	DetectHiddenWindows, % vDHW
	return vIsPaused
}
Last edited by jeeswg on 07 Jul 2017, 05:50, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script)

07 Jul 2017, 04:54

Hello, thanks for you efforts, I shall take a look.
The specific detail I had in mind was ahk's internal usage of the message 0x44.

Cheers.
Helgef
Posts: 4709
Joined: 17 Jul 2016, 01:02
Contact:

Re: list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script)

07 Jul 2017, 05:22

Excellent jeeswg! :bravo:
This is what I wanted,

Code: Select all

suspendAll(mode:="toggle"){
	; Change suspension state of all ahk scripts.
	; Mode, "toggle", "on" or "off".
	; All credits to jeeswg, https://autohotkey.com/boards/viewtopic.php?p=158041#p158041
	; All blame on helgef.
	DHW_Setting:=A_DetectHiddenWindows
	DetectHiddenWindows, On
	WinGet,scriptHwnds,List, % "ahk_class AutoHotkey"
	Loop, % scriptHwnds
		if (mode="toggle") || ((isSuspended:=JEE_AhkWinIsSuspended(scriptHwnds%A_Index%)) && mode="off") || (!isSuspended && mode="on")
			PostMessage, 0x111, 65404,,, % "ahk_id " scriptHwnds%A_Index%
	DetectHiddenWindows, % DHW_Setting
	return
}

JEE_AhkWinIsSuspended(hWnd){
	SendMessage, 0x211,,,, % "ahk_id " hWnd ;WM_ENTERMENULOOP := 0x211
	SendMessage, 0x212,,,, % "ahk_id " hWnd ;WM_EXITMENULOOP := 0x212
	hMenuBar := DllCall("GetMenu", Ptr,hWnd, Ptr)
	hMenuFile := DllCall("GetSubMenu", Ptr,hMenuBar, Int,0, Ptr)
	;ID_FILE_SUSPEND := 65404
	vState := DllCall("GetMenuState", Ptr,hMenuFile, UInt,65404, UInt,0, UInt)
	vIsSuspended := (vState >> 3) & 1
	DllCall("CloseHandle", Ptr,hMenuFile)
	DllCall("CloseHandle", Ptr,hMenuBar)
	return vIsSuspended
}
Example usage,

Code: Select all

q::
	Suspend,permit
	suspendAll("toggle")
return
w::
	Suspend,permit
	suspendAll("on")
return
e::
	Suspend,permit
	suspendAll("off")
return
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script)

07 Jul 2017, 05:34

Btw CloseHandle is wrong, it doesn't do menu handles. I'll have to investigate ...

[EDIT:] DeleteObject doesn't work either. It may be simply that you don't close it, it's just a read-only global ID you retrieve like an hWnd. (So I've edited my 2 functions to remove the 2 CloseHandle lines in each of them.)

Note: There is DestroyMenu, but we don't want to do that either.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
Cerberus
Posts: 172
Joined: 12 Jan 2016, 15:46

Re: list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script)

02 Jul 2018, 22:48

Very interesting! So I wonder, is it possible this way to get a list of all variables and objects that are in use by another script? If you do the ID_VIEW_VARIABLES command, is it possible to get a list and do something with it in the executing script (so no the script whose variables we want to view)?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script)

02 Jul 2018, 23:06

From here:
best utilities + best AutoHotkey scripts (+ useful tips) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=28149
[AutoHotkey script information direct to variable]
[function: ScriptInfo (get AHK main window text for active script only)]
ScriptInfo(): Get ListLines/ListVars/ListHotkeys/KeyHistory text - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=9656
[features code to get AHK main window text for external scripts]
test whether another script's hotkeys are still working (trigger hotkeys in another script) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=27839

[get variable text from other scripts]
DebugVars - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=24984
- ScriptInfo is a function, and DebugVars is a script, both by lexikos.
- ScriptInfo effectively shows the AHK main window, but keeps it hidden, and grabs text from it. It doesn't work on external AHK processes.
- qwerty12 wrote some code to apply ScriptInfo to an external AHK main window.
- DebugVars is an advanced script for retrieving variable info from an external AHK process.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
Cerberus
Posts: 172
Joined: 12 Jan 2016, 15:46

Re: list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script)

10 Aug 2019, 20:37

jeeswg wrote:
02 Jul 2018, 23:06
From here:
...
Hey, it seems I never saw your reply; I've just stumbled upon it. Thank you very much for the overview, and for explaining how those options work!

I have used Debug Vars in the past, and I believe Autohotkey Studio (or was it Scite for Autohotkey?) uses it in its debugging process, to show the variables of the debugged script. I may try to incorporate it into the debugger for Sublime Text which I once began to write (based on Lexikos's general debugger). I hope it will be possible to do so.
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: list of AutoHotkey WM_COMMAND IDs (e.g. Reload/Edit/Suspend/ListVars on another script)

17 Feb 2022, 18:51

Thanks @jeeswg.
I have added these to Ziggle.

Code: Select all


.data.
1028	AHK_NOTIFY
65300	AHK_TRAY_OPEN
65400	AHK_FILE_RELOADSCRIPT
65303	AHK_TRAY_RELOADSCRIPT
65401	AHK_FILE_EDITSCRIPT
65304	AHK_TRAY_EDITSCRIPT
65402	AHK_FILE_WINDOWSPY
65302	AHK_TRAY_WINDOWSPY
65403	AHK_FILE_PAUSE
65306	AHK_TRAY_PAUSE
65404	AHK_FILE_SUSPEND
65305	AHK_TRAY_SUSPEND
65405	AHK_FILE_EXIT
65307	AHK_TRAY_EXIT
65406	AHK_VIEW_LINES
65407	AHK_VIEW_VARIABLES
65408	AHK_VIEW_HOTKEYS
65409	AHK_VIEW_KEYHISTORY
65410	AHK_VIEW_REFRESH
65411	AHK_HELP_USERMANUAL
65301	AHK_TRAY_HELP
65412	AHK_HELP_WEBSITE
65402	AHK_FILE_WINDOWSPY
65302	AHK_TRAY_WINDOWSPY
65410	AHK_VIEW_REFRESH
65411	AHK_HELP_USERMANUAL
65301	AHK_TRAY_HELP
65412	AHK_HELP_WEBSITE


Return to “Tips and Tricks (v1)”

Who is online

Users browsing this forum: No registered users and 17 guests