Hi thanks for the code it was just what i'm looking for.. although i'm having trouble adapting it.
I want to switch between two windows every time i press "a" how would i change the script to release the focus and then reapply it? heres what i have so far but i'm not sure how to let the focus go.
WinGet, myarray, List, ahk_class ATL:00420130,,gamers
a::
SetBatchLines -1
Process, Priority,, High
DetectHiddenWindows, On ; Since Notepad is launched hidden
IfWinActive, ahk_id %myarray1%
{
;WinSet, AlwaysOnTop, Off, ahk_id %myarray1%
;WinSet, AlwaysOnTop, On, ahk_id %myarray2%
;WinActivate, ahk_id %myarray2%
;current = ahk_id %myarray2%
current = %myarray2%
goto, nextwin
}
IfWinActive, ahk_id %myarray2%
{
;WinSet, AlwaysOnTop, Off, ahk_id %myarray2%
;WinSet, AlwaysOnTop, On, ahk_id %myarray1%
;WinActivate, ahk_id %myarray0%
;current = ahk_id %myarray1%
current = %myarray1%
goto, nextwin
}
MsgBox, %current%
nextwin:
hnp := WinExist(ahk_id %current%) ; Obtain hwnd
WinSetUnMovable( hnp ) ; Make the window unmovable
;WinSet, AlwaysOnTop, On, ahk_id %hnp% ; Flag it Always-On-Top
; SHELLHOOK method to detect active window -----------------------------------------------
; Refer Tips N Tricks : http://www.autohotkey.com/forum/viewtopic.php?p=123323#123323
Gui +LastFound
hWnd := WinExist()
DllCall( "RegisterShellHookWindow", UInt,hWnd )
MsgNum := DllCall( "RegisterWindowMessage", Str,"SHELLHOOK" )
OnMessage( MsgNum, "ShellMessage" )
; ----------------------------------------------------------------------------------------
OnExit, QuitScript
WinActivate, ahk_id %hnp%
Return ; // End of Auto-Execute Section //
ShellMessage( wParam,lParam ) {
global hnp
If ( wParam=4 && lParam<>hnp ) ; any window other than notepad is activated
WinActivate, ahk_id %hnp%
If ( wParam=2 && lParam=hnp ) ; if Notepad window is closed/destroyed
ExitApp
}
WinSetUnMovable( hwnd ) {
hSysMenu:=DllCall("GetSystemMenu","Int",hWnd,"Int",FALSE)
nCnt:=DllCall("GetMenuItemCount","Int",hSysMenu)
DllCall("RemoveMenu","Int",hSysMenu,"UInt",nCnt-6,"Uint","0x400")
DllCall("DrawMenuBar","Int",hWnd)
}
QuitScript:
;PostMessage, 0x112, 0xF060,,, ahk_id %hnp%
ExitApp
Return