How to toggle an AHK script on/off with a key? - autohotkey

I'm working on a Script that constrains the movement of the cursor to the horizontal direction only. I would like to activate and deactivate it using the same hotkey.
I'm using this code:
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
!s:: ; Hotkey will toggle status
Confine := !Confine
MouseGetPos, , SetY
ClipCursor( Confine, 0, SetY, A_ScreenWidth, SetY+1 )
return
!a::
Pause
Suspend
return
ClipCursor( Confine=True, x1=0 , y1=0, x2=1, y2=1 ) {
VarSetCapacity(R,16,0), NumPut(x1,&R+0),NumPut(y1,&R+4),NumPut(x2,&R+8),NumPut(y2,&R+12)
Return Confine ? DllCall( "ClipCursor", UInt,&R ) : DllCall( "ClipCursor" )
}
The code works, but when pressing ctrl + a the script doesn't stop.
Am I using incorrectly the pause and suspend commands? How could this task be done?

That's a neat function! I can definitely see some use for that. Anyway, you are correctly using Pause and Suspend, but it appears that !s was meant to toggle it on and off (so, no need for !a).
For some reason, though, it won't toggle off. In my testing, the function was correctly seeing the value of "Confine", but wasn't returning the false-portion of the ternary operation. It appears to be coded properly, but I suspect there may be an issue (possible bug?) with Return evaluating "Confine" properly.
Here are a few solutions:
By testing explicitly whether "Confine" is equal to True works.
Return ( Confine = True ) ? DllCall( "ClipCursor" , UInt , &R ) : DllCall( "ClipCursor" )
What I would do, however, is take the ternary operation out of the function and move it to your hotkey to avoid needless operations and assignments if it evaluates to false. To me, this is a bit cleaner.
!s:: ; Hotkey will toggle status
Confine := !Confine
MouseGetPos ,, SetY
Confine ? ClipCursor( 0 , SetY , A_ScreenWidth , SetY+1 ) : DllCall( "ClipCursor" )
Return
ClipCursor( x1=0 , y1=0 , x2=1 , y2=1 ) {
VarSetCapacity( R , 16 , 0 )
NumPut( x1 , &R + 0 )
NumPut( y1 , &R +4 )
NumPut( x2 , &R +8 )
NumPut( y2 , &R +12 )
Return DllCall( "ClipCursor" , UInt , &R )
}
If you just want to use !a to turn it off, you could just do this, !a::DllCall( "ClipCursor" ). If you decide to go this route, I would recommend removing all of the toggle portions of code from the hotkey and function.

Related

Dual monitor help needed [AutoHotkey]

I'm having trouble getting my script to work on multiple monitors, having searched and found some posts regarding the use of multiple monitors I''m still not sure where I am going wrong and how to fix it.
I am currently using a laptop with an external monitor connected, but I will be sharing this with colleagues who may not have additional monitors. When I run on an application on the main screen (Laptop screen) everything seems to work as expected but when I run it on an application on the additional monitor the coordinates seem to be off.
Please see my code below, I know this may be a mess and could be cleaned up but I'm not quite that knowledgable yet.
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
If !FileExist( "Settings.ini" ) {
If ( WinExist("Amazon WorkSpaces") )
{
WinActivate
} Else
{
MsgBox, 48, Auto Clicker, Open AWS!
}
MsgBox Please close this message and click Start Tracing button
KeyWait, LButton, Down
MouseGetPos, tracingx, tracingy
KeyWait, LButton, Up
MouseGetPos, tracingendx, tracingendy
AHKCommand = %tracingx%, %tracingy%
IniWrite, %tracingx%, Settings.ini, tracing, xcoord
IniWrite, %tracingy%, Settings.ini, tracing, ycoord
MsgBox Please close this message and click Back to consignment list button
KeyWait, LButton, Down
MouseGetPos, backx, backy
KeyWait, LButton, Up
MouseGetPos, backendx, backendy
AHKCommand2 = %backx%, %backy%
IniWrite, %backx%, Settings.ini, back, xcoord
IniWrite, %backy%, Settings.ini, back, ycoord
InputBox, minrefresh, Minimum Refresh, Enter Minimum refresh time in milliseconds (1 min = 60000 milliseconds), , , , , , , , 180000
IniWrite, %minrefresh%, Settings.ini, refresh rates, min
InputBox, maxrefresh, Maximum Refresh, Enter Maximum refresh time in milliseconds (1 min = 60000 milliseconds), , , , , , , , 300000
IniWrite, %maxrefresh%, Settings.ini, refresh rates, max
Return ; This stops the script or returns from the above subroutine.
; ExitApp ; This exits the script entirely
; GoSub, Start ; This jumps to the label start in the script.
; Use non of these to continue the script
}
InputBox, minrefresh, Minimum Refresh, Enter Minimum refresh time in milliseconds (1 min = 60000 milliseconds), , , , , , , , 60000
IniWrite, %minrefresh%, Settings.ini, refresh rates, min
InputBox, maxrefresh, Maximum Refresh, Enter Maximum refresh time in milliseconds (1 min = 60000 milliseconds), , , , , , , , 180000
IniWrite, %maxrefresh%, Settings.ini, refresh rates, max
^+z:: ; Control+Shift+Z hotkey.
IniRead, tracingx, Settings.ini, tracing, xcoord
IniRead, tracingy, Settings.ini, tracing, ycoord
IniRead, backx, Settings.ini, back, xcoord
IniRead, backy, Settings.ini, back, ycoord
AHKCommand = %tracingx%, %tracingy%
AHKCommand2 = %backx%, %backy%
Random, rand, %minrefresh%, %maxrefresh%
Loop {
If ( WinExist("Amazon WorkSpaces") )
{
WinActivate
PixelGetColor, color, %tracingx%, %tracingy%
If (color = 0xEFEFEF) {
Click %AHKCommand%
Sleep, 2000
PixelGetColor, color, %backx%, %backy%
If (color = 0xF5F5F5) {
Click %AHKCommand2%
Sleep, 2000
} Else
{
MsgBox, , Auto Clicker, You have a call!
}
} Else
{
MsgBox, 48, Auto Clicker, Check Settings!]
}
} Else
{
MsgBox, 48, Auto Clicker, Open AWS!
}
Sleep, %rand%
}
What I hope to happen is on starting the script it checks for settings and if it doesn't find them it will ask you for the information. once this check is done it will click a set location from the data you provided at an interval set by yourself and check it matches the specific colour (button present/not present) then displays errors or messages as required. Pretty simple so far?
The problem comes when I have the application on the additional monitor. At first, I thought nothing was happening, but with a msgbox here and there I can now see that the coordinates I selected during setup are correct but when the script is running the coordinates seem to be off by a varying amount (Currently between 105 & 120px on the x-axis and between 145 & 147px on the y-axis.
Is this going to work, or should I give up and get everyone using it on the main laptop screen?

Problems with a code that constrains the movement of the cursor to the horizontal direction

I'm using a code that constrains the movement of the cursor to the horizontal direction when it is activated, but I have experienced the following issue: when toggling on the script, the cursor gets displaced down from its original position, instead of remaining at the same height.
The code I'm using is this one:
!s:: ; Hotkey will toggle status
Confine := !Confine
MouseGetPos ,, SetY
Confine ? ClipCursor( 0 , SetY , A_ScreenWidth , SetY+1 ) : DllCall( "ClipCursor" )
Return
ClipCursor( x1=0 , y1=0 , x2=1 , y2=1 ) {
VarSetCapacity( R , 16 , 0 )
NumPut( x1 , &R + 0 )
NumPut( y1 , &R +4 )
NumPut( x2 , &R +8 )
NumPut( y2 , &R +12 )
Return DllCall( "ClipCursor" , UInt , &R )
}
I need the cursor not to jump. How could this behavior be fixed?
This question is related to another one that I posted previously:
How to toggle an AHK script on/off with a key?
The coordinate SetY has to be relative to the desktop (entire screen).
!s:: ; Hotkey will toggle status
Confine := !Confine
CoordMode, Mouse, Screen ; If this command is not used the coordinates are relative to the active window.
MouseGetPos ,, SetY
If (Confine)
ClipCursor( Confine, 0, SetY, A_ScreenWidth+1, SetY+1 )
else
DllCall( "ClipCursor" )
Return
ClipCursor( Confine=True, x1=0 , y1=0 , x2=1 , y2=1 ) {
VarSetCapacity( R , 16 , 0 )
NumPut( x1 , &R + 0 )
NumPut( y1 , &R +4 )
NumPut( x2 , &R +8 )
NumPut( y2 , &R +12 )
Return DllCall( "ClipCursor" , UInt , &R )
}
https://www.autohotkey.com/docs/commands/CoordMode.htm

How do you include a loop with modifiers?

I'm trying to get AHK to continue to press "2" until "2" is pressed a second time. If alt, ctrl, or shift is held it sends ^2, +2, !2 while held and then returns to spamming "2" once the modifier key is released.
This code works so far with modifiers I just need to figure out how to add the loop.
; Disable Alt+Tab
!Tab::Return
; Disable Windows Key + Tab
#Tab::Return
#ifWinActive World of Warcraft
{
$2::
$^2::
$+2::
$!2::
Loop
{
if not GetKeyState("2", "P")
break
if GetKeyState("LCtrl", "P")
Send ^2
else if GetKeyState("LShift", "P")
Send +2
else if GetKeyState("LAlt", "P")
Send !2
else
Send 2
sleep 135
}
return
}
I would recommend using SetTimer for your loop and to be able to toggle it on and off. Please see if the following works for you:
$2::
$<^2::
$<+2::
$<!2::
SetTimer , label_TwoLoop , % ( bT := !bT ) ? "135" : "Off"
Return
label_TwoLoop:
If GetKeyState( "LCtrl" , "P" )
Send , ^2
Else If GetKeyState( "LShift" , "P" )
Send , +2
Else If GetKeyState( "LAlt" , "P" )
Send , !2
Else
Send , 2
Return
https://autohotkey.com/docs/commands/SetTimer.htm
Note that I added the < to the hotkey definitions since the loop-portion is only looking for the left modifier keys. I figured this is the intended behavior.

How to achieve visual-studio-like chained hotkeys using AHK?

I'm trying to achieve a visual-studio-like chaining of hotkeys for something at work.
Basically, when I hit Ctrl+Alt+F, I want to enter a sort of "Format mode" The next key I press will determine what text is injected. I'd like "Format mode" to cease as soon as one of the inner hotkeys is pressed. However I'd also like the option to have to cancel it manually just in case.
I've tried searching for the chaining of hotkeys, as well as attempted the following, rather naive code:
;
;; Format Mode
;
^+f::
; Bold
b::
Send "<b></b>"
Send {Left 4}
return
; Italics
i::
Send "<i></i>"
Send {Left 4}
return
; Bulleted List
u::
Send "<u></u>"
Send {Left 4}
return
; Numbered List
o::
Send "<o></o>"
Send {Left 4}
return
; List Item
l::
Send "<li></li>"
Send {Left 4}
return
; Line Break
r::
Send "<br/>"
return
return
I was pretty sure this wasn't going to work, but I figured I'd give it a shot so as to not make y'all think I'm just asking to be spoon fed.
I haven't worked with AHK a whole lot, but I've used it enough to be able to accomplish some stuff both at home and at work, but it's suuuuper messy - just as some background as to my experience with AHK.
With the #if command you are able to Switch/Toggle between action1/Enable and action2/Disable with the same Hotkeys.
You can test it out in Notepad. if you then type the key t
type Ctrl+Shift+f keys to toggle between two the same hotkeys.
Note: For your Hotkeys You Can Change the Code a Little Bit! you can Place all your hotkeys into #if Mode1 and then use no hotkeys into #if Mode2
Example1.ahk
; [+ = Shift] [! = Alt] [^ = Ctrl] [# = Win]
#SingleInstance force
a := 1
#If mode1 ; All hotkeys below this line will only work if mode1 is TRUE or 1
t::
send 1
; Here you can put your first hotkey code
return
; Here you can Place All your Hotkeys
#If
#If mode2 ; All hotkeys below this line will only work if mode2 is TRUE or 1
t::
send 2
; And here you can put your second hotkey code
return
#If
; toggle between [t::1] and [t::2]
;a = 1 => t::1
;a = 2 => t::2
;type Ctrl+Shift+f keys to toggle between two the same hotkeys
;you can test it out in notepad - if you then type the key t
^+f::
if (a=1)
{
mode1 = 1
mode2 = 0
a := 2
}else{
mode1 = 0
mode2 = 1
a := 1
}
return
esc::exitapp
Using #If is a good choice, as stevecody showed. Below is another solution that may work for you. It uses your ^+f hotkey to activate the specialty hotkeys. The specialty hotkeys will also deactivate themselves upon use. f1 is your option to cancel it manually.
^+f::
Hotkey , b , l_Bold , On
Hotkey , i , l_Italics , On
Hotkey , l , l_ListItem , On
Return
f1::
Hotkey , b , l_Bold , Off
Hotkey , i , l_Italics , Off
Hotkey , l , l_ListItem , Off
Return
l_Bold:
Hotkey , b , l_Bold , Off
Send , <b></b>{left 4}
Return
l_Italics:
Hotkey , i , l_Italics , Off
Send , <i></i>{left 4}
Return
l_Italics:
Hotkey , l , l_ListItem , Off
Send , <li></li>{left 5}
Return
Something else I was looking at, but it doesn't quite work right, is below. The problem is that it will still send the specialty key and you end up with something like <i>i</i> instead of <i></i>.
f1::
KeyBdHook := DllCall( "SetWindowsHookEx" , "int" , 13 , "uint" , RegisterCallback( "KeyBdProc" ) , "uint" , 0 , "uint" , 0 )
input
Return
KeyBdProc( nCode , wParam , lParam )
{
global KeyBdHook
Critical
If ( wParam = 0x100 )
{
DllCall( "UnhookWindowsHookEx" , "ptr" , KeyBdHook )
sKey := GetKeyName( Format( "vk{:x}" , NumGet( lParam + 0 , 0 , "int" ) ) )
If ( sKey = "i" )
Send , <i></i>{left 4}
Else
MsgBox , You pressed %sKey%
}
}

AutoHotKey - How to add a click handler to a displayed program's icon in a GUI?

The examples that I've found that display a program's icon on a GUI form all seem to use a text control to indicate where the icon is to be displayed, but then send the STM_SETICON messages to actually display the image. However, the text control's event subroutine that handles mouse clicks are never get called when I click on the displayed icon. I've considered displaying a transparent graphic area over the icon with its own event subroutine, but seems like I should be able to attach the event handler directly to the icon's display area or load the icon into a graphic control with its own event handler.
Anyone know how to do either of these?
I am using AutoHotKey L (v 1.1.09.04) 64 bit on Windows 7 Pro.
Here is the code I found while searching for a way to display the icon, which I am now using.
FileName := "C:\XXXX\XXXX.exe" ; Get the icon from a program file.
Ignored := 0
;
; CopyImage into memory and scale it to size.
;
IMAGE_ICON := 1
LR_COPYFROMRESOURCE := 4
LR_COPYDELETEORG := 8
IconSize := 16 ; Icon size: X by X
ptr := ( ( A_PtrSize = 8 ) ? "ptr" : "uint" )
sfi_size := A_PtrSize + 8 + ( ( A_IsUnicode ) ? 680 : 340 )
VarSetCapacity( sfi, sfi_size )
DllCall( "Shell32\SHGetFileInfo" . ( ( A_IsUnicode ) ? "W" : "A" )
, "str", FileName
, "uint", Ignored
, ptr, &sfi
, "uint", sfi_size
, "uint", SHGFI_ICON )
hIcon := NumGet( sfi, 0 )
hicon_resized := DllCall( "CopyImage"
, ptr, hicon
, "uint", IMAGE_ICON
, "int", IconSize
, "int", IconSize
, "uint", LR_COPYFROMRESOURCE | LR_COPYDELETEORG
, ptr )
DllCall( "DestroyIcon", ptr, hicon )
STM_SETICON := 0x0170
Gui, Add, Text, x5 y8 w%IconSize% h%IconSize% hwndMyPic %SS_ICON% gClicked
SendMessage, STM_SETICON, hicon_resized, 0,, Ahk_ID %MyPic%
I want to change the icon to be embedded in my script and to also use is a the taskbar and tray icon, and I want this to all work without having to compile the script.
Could it be that you are looking for the way to change the tray icon for any running script? Here is an example where I borrow an icon from Shell32.dll:
Menu, Tray, Tip, My Application
Menu, Tray, Icon , Shell32.dll, 28, 1
By using:
menu, tray, add
You could also add to (or replace) the tray menu
A long time ago SKAN showed how to include an icon inside a script.
http://www.autohotkey.com/board/topic/31044-crazy-scripting-include-an-icon-in-your-script/
Here is what I tried:
#NoTrayIcon
IconDataHex =
( LTrim Join
0000010001002020080000000000A8080000160000002800000020000000400000000100080000000000000400
000000000000000000000000000000000000000000000080000080000000808000800000008000800080800000
C0C0C000C0DCC000F0CAA6000020400000206000002080000020A0000020C0000020E000004000000040200000
40400000406000004080000040A0000040C0000040E00000600000006020000060400000606000006080000060
A0000060C0000060E00000800000008020000080400000806000008080000080A0000080C0000080E00000A000
0000A0200000A0400000A0600000A0800000A0A00000A0C00000A0E00000C0000000C0200000C0400000C06000
00C0800000C0A00000C0C00000C0E00000E0000000E0200000E0400000E0600000E0800000E0A00000E0C00000
E0E00040000000400020004000400040006000400080004000A0004000C0004000E00040200000402020004020
400040206000402080004020A0004020C0004020E00040400000404020004040400040406000404080004040A0
004040C0004040E00040600000406020004060400040606000406080004060A0004060C0004060E00040800000
408020004080400040806000408080004080A0004080C0004080E00040A0000040A0200040A0400040A0600040
A0800040A0A00040A0C00040A0E00040C0000040C0200040C0400040C0600040C0800040C0A00040C0C00040C0
E00040E0000040E0200040E0400040E0600040E0800040E0A00040E0C00040E0E0008000000080002000800040
0080006000800080008000A0008000C0008000E00080200000802020008020400080206000802080008020A000
8020C0008020E00080400000804020008040400080406000804080008040A0008040C0008040E0008060000080
6020008060400080606000806080008060A0008060C0008060E000808000008080200080804000808060008080
80008080A0008080C0008080E00080A0000080A0200080A0400080A0600080A0800080A0A00080A0C00080A0E0
0080C0000080C0200080C0400080C0600080C0800080C0A00080C0C00080C0E00080E0000080E0200080E04000
80E0600080E0800080E0A00080E0C00080E0E000C0000000C0002000C0004000C0006000C0008000C000A000C0
00C000C000E000C0200000C0202000C0204000C0206000C0208000C020A000C020C000C020E000C0400000C040
2000C0404000C0406000C0408000C040A000C040C000C040E000C0600000C0602000C0604000C0606000C06080
00C060A000C060C000C060E000C0800000C0802000C0804000C0806000C0808000C080A000C080C000C080E000
C0A00000C0A02000C0A04000C0A06000C0A08000C0A0A000C0A0C000C0A0E000C0C00000C0C02000C0C04000C0
C06000C0C08000C0C0A000F0FBFF00A4A0A000808080000000FF0000FF000000FFFF00FF000000FF00FF00FFFF
0000FFFFFF00FFFFFFFFFFFFFFF607F707F6F6FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6
E49A525BA40708F6FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBE0D8D89991525BA407F6F6FFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE2E8D8D8D8D8D899925B9BF707F6F6FFFFFFFFFFFFFFFFFFFFFFFF
FFFFFFFFFFE2E8D8D8D8D0D0D8D8D899525B9BF707F6F6FFFFFFFFFFFFFFFFFFFFFFFFFFFFE2E9D0D0D0D0D0D0
D0D0D8D8D899525BA4F708FFFFFFFFFFFFFFFFFFFFFFFFFFE2E9D092DB929191D8D0D0D0D0D8D8D8999AA4F6FF
FFFFFFFFFFFFFFFFFFFFFFE2E990DBE4E4E4DB929191D8D090D0D8D8D9A4F6FFFFFFFFFFFFFFFFFFFFFFFFE2E9
90DBE4E4E408BFE4DB929191D8D8D8D9A4F6FFFFFFFFFFFFFFFFFFFFFFFFE2E9909BE4E4E4B7BF07070807E492
91D8D9A4F6FFFFFFFFFFFFFFFFFFFFFFFFE2E99092DBDBE4F777E5BFBFBFBFBFE491D9A4F6FFFFFFFFFFFFFFFF
FFFFFFFFE2EA9092DBDBDBDBE4E4AEAEF7B67FED92D9A4F6FFFFFFFFFFFFFFFFFFFFFFFFE2EA9092DBDBDBDBDB
DBDBE4E4E4F7E492D9A4F6FFFFFFFFFFFFFFFFFFFFFFFFE2EA9092D2DBDBDBDBDBDBDBDBDBE4DB92D9A4F6FFFF
FFFFFFFFFFFFFFFFFFFFE2F29092D2D2DBDBDBDBDBDBDBDBDBDB9299A4F6FFFFFFFFFFFFFFFFFFFFFFFFE2F290
92D2D2D2D2DBDBDBDBDBDBDBDB9299A4F6FFFFFFFFFFFFFFFFFFFFFFFFE3FFD192D2D2D2D2D2D2D2D2D2D2D2D2
9291A4F6FFFFFFFFFFFFFFFFFFFFFFFF09F3D992D2D2D2D2D2D2D2D2D2D2D2D29291A4F6FFFFFFFFFFFFFFFFFF
FFFFFF09F3D989D2D2D2D2D2D2D2D2D2D2D2D29291A4F6FFFFFFFFFFFFFFFFFFFFFFFF09F3D98992D2D2D2D2D2
D2D2D2D2D2929291A4F6FFFFFFFFFFFFFFFFFFFFFFFF09F3D9899292929292929292929292929291A4F6FFFFFF
FFFFFFFFFFFFFFFFFF0909D9499192929292929292929292929291A4F6FFFFFFFFFFFFFFFFFFFFFFFFECEB9149
4949494949494949494949499291A4F6FFFFFFFFFFFFFFFFFFFFFFFFECEB904949494949494949494949494992
91F7FFFFFFFFFFFFFFFFFFFFFFFFFFECEB90494949494949494949494949499292F7F6FFFFFFFFFFFFFFFFFFFF
FFFFECEB90494949494949494949494949498991A4F6FFFFFFFFFFFFFFFFFFFFFFFFECEB904949404040404949
49494949498991A4F6FFFFFFFFFFFFFFFFFFFFFFFFECEB90914949494949494040494949494991A4F6FFFFFFFF
FFFFFFFFFFFFFFFFECEB90909090909191919149494949499191A4F6FFFFFFFFFFFFFFFFFFFFFFFF09FFE2DAD9
D1909090909090909091919091A4F6FFFFFFFFFFFFFFFFFFFFFFFF0909EBECE2EBE2EAE2E2D9D9D0D0D0909091
F7F6FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF0909ECECEBE3E2D9D8D9ECF6FFFFFFFFFFFFFF0000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000000000000000
)
VarSetCapacity( IconData,( nSize:=StrLen(IconDataHex)//2) )
Loop %nSize% ; MCode by Laszlo Hars: http://www.autohotkey.com/forum/viewtopic.php?t=21172
NumPut( "0x" . SubStr(IconDataHex,2*A_Index-1,2), IconData, A_Index-1, "Char" )
IconDataHex := "" ; contents needed no more
hICon := DllCall( "CreateIconFromResourceEx", UInt,&IconData+22
, UInt,NumGet(IconData,14), Int,1, UInt,0x30000, Int,32, Int,32, UInt,0 )
Gui +LastFound ; Set our GUI as LastFound window ( affects next two lines )
SendMessage, ( WM_SETICON:=0x80 ), 0, hIcon ; Set the Titlebar Icon
SendMessage, ( WM_SETICON:=0x80 ), 1, hIcon ; Set the Alt-Tab icon
PID := DllCall("GetCurrentProcessId"), VarSetCapacity( NID,444,0 ), NumPut( 444,NID )
DetectHiddenWindows, On
NumPut( WinExist( A_ScriptFullPath " ahk_class AutoHotkey ahk_pid " PID),NID,4 )
DetectHiddenWindows, Off
NumPut( 1028,NID,8 ), NumPut( 2,NID,12 ), NumPut( hIcon,NID,20 )
Menu, Tray, Icon ; Shows the default Tray icon
DllCall( "shell32\Shell_NotifyIcon", UInt,0x1, UInt,&NID ) ; and we immediately modify it.
Gui, Show, w640 h480
Return
GuiClose:
ExitApp
It opens an empty GUI but it HAS CHANGED THE tray Icon, The GUI Icon and the Alt+Tab icon.