Page 1 of 1
AutoClose Brackets
Posted: 03 Oct 2019, 09:10
by Rafio
Is it possible in AutoGui to programmatically toggle AutoClose Brackets?
I would like to disable this funcion before sending hotstrings and re-enable it just after.
Thanks.
Re: AutoClose Brackets
Posted: 03 Oct 2019, 10:34
by kczx3
Maybe just paste the contents instead of using the hotstring to "type" the text.
https://www.autohotkey.com/boards/viewtopic.php?t=39078
Re: AutoClose Brackets
Posted: 05 Oct 2019, 08:23
by Rafio
Thanks, but it does not solve my problem.
Is it possible to use gui scripting to trigger the menu item?
Re: AutoClose Brackets
Posted: 11 Oct 2019, 05:00
by Alguimist
Rafio wrote: ↑03 Oct 2019, 09:10
Is it possible in AutoGui to programmatically toggle AutoClose Brackets?
I would like to disable this funcion before sending hotstrings and re-enable it just after.
Try this:
Code: Select all
::rc::
ToggleBrackets()
Send VarSetCapacity(RECT, 16, 0)
ToggleBrackets()
Return
ToggleBrackets() {
TopMenu := " &Options "
MenuItem := "Autoclose &Brackets"
WinMenuSelectItem A,, %TopMenu%, %MenuItem%
}
Re: AutoClose Brackets
Posted: 14 Oct 2019, 07:08
by Rafio
Thanks, Alguimist.
And my appologies for being so late to respond.
The script is fine but:
could we know if the menu item is checked prior to select it?
Re: AutoClose Brackets Topic is solved
Posted: 15 Oct 2019, 15:35
by Alguimist
Rafio wrote:could we know if the menu item is checked prior to select it?
You can do it with the Windows API function GetMenuState.
Code: Select all
Global g_AppName := "AutoGUI"
, g_TopMenu := " &Options "
, g_MenuItem := "Autoclose &Brackets"
::rc::
Enabled := IsAutocloseBracketEnabled() ; Store current state
If (Enabled == -1) {
Return
}
EnableAutocloseBrackets(0) ; Disable
Send VarSetCapacity(RECT, 16, 0)
If (Enabled) {
EnableAutocloseBrackets(1) ; Restore
}
Return
EnableAutocloseBrackets(Enable := True) {
AutocloseBracketsEnabled := IsAutocloseBracketEnabled()
If ((!Enable && AutocloseBracketsEnabled) || (Enable && !AutocloseBracketsEnabled)) {
WinMenuSelectItem A,, %g_TopMenu%, %g_MenuItem%
}
}
IsAutocloseBracketEnabled() {
WinGet hWnd, ID, %g_AppName% v ahk_class AutoHotkeyGUI
If (!hWnd) {
MsgBox 0x10, Error, The window could not be found.
Return -1
}
hMenu := GetMenu(hWnd)
OptionsMenuPos := FindMenuPos(hMenu, g_TopMenu)
hMenuOptions := GetSubMenu(hMenu, OptionsMenuPos)
AutocloseBracketsPos := FindMenuPos(hMenuOptions, g_MenuItem)
Return IsMenuItemChecked(hMenuOptions, AutocloseBracketsPos)
}
FindMenuPos(hMenu, MenuString) {
MenuItemCount := GetMenuItemCount(hMenu)
Loop %MenuItemCount% {
If (GetMenuString(hMenu, A_Index - 1) = MenuString) {
Return A_Index - 1 ; Zero-based
}
}
Return -1
}
GetMenu(hWnd) {
Return DllCall("GetMenu", "Ptr", hWnd, "Ptr")
}
GetSubMenu(hMenu, nPos) {
Return DllCall("GetSubMenu", "Ptr", hMenu, "UInt", nPos, "Ptr")
}
GetMenuItemCount(hMenu) {
Return DllCall("GetMenuItemCount", "Ptr", hMenu)
}
GetMenuItemID(hMenu, nPos) {
Return DllCall("GetMenuItemID", "Ptr", hMenu, "UInt", nPos)
}
GetMenuString(hMenu, uIDItem) { ; zero-based
Local lpString, MenuItemID
VarSetCapacity(lpString, 4096)
If !(DllCall("GetMenuString", "Ptr", hMenu, "UInt", uIDItem, "Str", lpString, "UInt", 4096, "UInt", 0x400)) {
MenuItemID := GetMenuItemID(hMenu, uIDItem)
If (MenuItemID > -1) {
Return "SEPARATOR"
} Else {
Return (GetSubMenu(hMenu, uIDItem)) ? "SUBMENU" : "ERROR"
}
}
Return lpString
}
IsMenuItemChecked(hMenu, Pos) {
MenuState := DllCall("GetMenuState", "Ptr", hMenu, "UInt", Pos, "UInt", 0x400) ; By position
Return MenuState & 0x8 ; MF_CHECKED
}
Note: I'm considering to implement expansion of abbreviations as a built-in functionality, but this will take some time.
Re: AutoClose Brackets
Posted: 16 Oct 2019, 11:48
by Rafio
Perfect!
I have modified your script to make it a unique function that only desables the menu item.
Problem solved.