kcvinu Posted January 21, 2015 Posted January 21, 2015 Hi there, I am planning to customize ALT TAB key combination. This is my pseudo code Get window list with WinList() If Mywindow1 and Mywindow2 is Exits Then Toggle that two windows. Else Find last active window and activate it. So i need to know how to find the last active window.? Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
MikahS Posted January 21, 2015 Posted January 21, 2015 (edited) You would do something like so: Local $myLastWin = WinActive("[ACTIVE]") ; your code goes after Local $winList = WinList() Local $Mywindow1 = "handle for window 1 here", $MyWindow2 = "handle for window 2 here" If WinExists($Mywindow1) And WinExists($Mywindow2) Then ; toggle the windows Else WinActivate($myLastWin) EndIf Does that help? Edited January 21, 2015 by MikahS kcvinu 1 Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
iamtheky Posted January 21, 2015 Posted January 21, 2015 just send alt+tab as pressing alt+tab once takes you to the last active window. But it would take more effort to find your script and run it than it would to just press alt+tab. kcvinu 1 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
kcvinu Posted January 21, 2015 Author Posted January 21, 2015 Hi MikahS, I didn't get the first line of your code. What is "[Active]" ? Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
kcvinu Posted January 21, 2015 Author Posted January 21, 2015 Hi boththose, Thanks but Send is not working Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
MikahS Posted January 21, 2015 Posted January 21, 2015 (edited) Hi MikahS, I didn't get the first line of your code. What is "[Active]" ? [ACTIVE] is the window that is active right now. Storing the returned result (which is the handle) in a variable will give you the ability to use WinActivate to re-activate the window that you want. EDIT: see the title special definiton Edited January 21, 2015 by MikahS kcvinu 1 Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
kcvinu Posted January 21, 2015 Author Posted January 21, 2015 Hi MikahS Thanks. Let me try Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
kcvinu Posted January 21, 2015 Author Posted January 21, 2015 Hi MikahS, It is partially working now. See my code. (Attached image). Code in line number 21 is not working. Rest is ok. Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
MikahS Posted January 21, 2015 Posted January 21, 2015 (edited) The reason is probably due to if $Nuendo_hnd and $Word_hnd are both existing (or they are open windows), line 21 will never run. The only way you'll be able to get it to do line 21 is if Nuendo or MS word did not exist. If you only had one window that exists like MS word then it would run, but not with both open. EDIT: does that help clear it up? Edited January 21, 2015 by MikahS Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
iamtheky Posted January 21, 2015 Posted January 21, 2015 send works fine If not winexists("Microsoft Word") AND not winexists("nuendo") Then send("!{TAB}") ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
kcvinu Posted January 21, 2015 Author Posted January 21, 2015 It is not working even when both "Nuendo" and "Word" is not running.. Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
MikahS Posted January 21, 2015 Posted January 21, 2015 (edited) on line 10 use WinGetTitle("[ACTIVE]") instead of WinActive. I think it was a problem trying to use the handle instead of a title. EDIT: Try that and post results. Edited January 21, 2015 by MikahS kcvinu 1 Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
iamtheky Posted January 21, 2015 Posted January 21, 2015 (edited) It is not working even when both "Nuendo" and "Word" is not running.. Makes me think we are troubleshooting your If statement, not the line suggested. Did you try running just the line I provided by itself? Edited January 21, 2015 by boththose ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
jguinch Posted January 21, 2015 Posted January 21, 2015 (edited) Can you try this ? expandcollapse popup$hPreviousWindow = _WinGetNextWindow("[ACTIVE]" , "", 2) ConsoleWrite("Previous Window : " & @CRLF & "HWND = " & $hPreviousWindow & @CRLF & "Title = " & WinGetTitle($hPreviousWindow) & @CRLF) ; #FUNCTION# ==================================================================================================================== ; Name ..........: _WinGetNextWindow ; Description ...: Retrieves a handle to the next or previous visible window in the Z-Order. ; Syntax ........: _WinGetNextWindow($vWindow[, $sText = ""[, $iCmd = 0]]) ; Parameters ....: $vWindow - The title/hWnd/class of the window. See Title special definition. ; $sText - [optional] The text of the window to check. Default is an empty string. See Text special definition. ; $iOrder - [optional] Indicates whether the function returns a handle to the next window or the previous window. ; This parameter can be either of the following values : ; $GW_HWNDNEXT (2) : Returns a handle to the window below the given window. ; $GW_HWNDPREV (3) : Returns a handle to the window above the given window. ; Return values .: Success - Returns a window handle ; Failure - Returns 0 and sets @error flag to non-zero on error ; Author ........: jguinch ; Remarks .......: If the specified window is a topmost window, the function searches for a topmost window. ; If the specified window is a top-level window, the function searches for a top-level window. ; If the specified window is a child window, the function searches for a child window. ; Link ..........: ; =============================================================================================================================== Func _WinGetNextWindow($vWindow, $sText = "", $iCmd = 2) Local $hWnd = $vWindow, $aGetWindow If NOT IsHWnd($vWindow) Then $hWnd = WinGetHandle($vWindow, $sText) If $hWnd = 0 Then Return SetError(2, 0, 0) If NOT IsDeclared("GW_HWNDNEXT") Then Local Const $GW_HWNDNEXT = 2 If NOT IsDeclared("GW_HWNDPREV") Then Local Const $GW_HWNDPREV = 3 If $iCmd <> $GW_HWNDNEXT AND $iCmd <> $GW_HWNDPREV Then Return SetError(3, 0, 0) While 1 $aGetWindow = DllCall("User32.dll", "hwnd", "GetWindow", "hwnd", $hWnd, "uint", $iCmd) If @error Then Return SetError(4, 0, 0) If $aGetWindow[0] = 0 Then ExitLoop $hWnd = $aGetWindow[0] $aGetWindowLong = DllCall("User32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", -16) If @error Then ExitLoop If NOT BitAND(WinGetState($hWnd), 2) OR $aGetWindowLong[0] < 0 Then ContinueLoop Return $hWnd WEnd Return SetError(1, 0, 0) EndFunc Edited January 21, 2015 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Moderators SmOke_N Posted January 21, 2015 Moderators Posted January 21, 2015 Are you running your script from SciTe? I imagine when you hit F5 from SciTe to test, that's the last active window? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
jguinch Posted January 21, 2015 Posted January 21, 2015 SmOke_N : your question is for me ? When I run my code, the Previous Window is How to find last active window ? - General Help and Support - AutoIt Forums - Mozilla Firefox Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
Solution jdelaney Posted January 21, 2015 Solution Posted January 21, 2015 (edited) Simplified with the Winapi UDF: #include <WinAPI.au3> $hPriorActiveWindow = _WinAPI_GetWindow(WinGetHandle("[ACTIVE]"),$GW_HWNDNEXT) WinActivate($hPriorActiveWindow) Edited January 21, 2015 by jdelaney kcvinu 1 IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
kcvinu Posted January 22, 2015 Author Posted January 22, 2015 Makes me think we are troubleshooting your If statement, not the line suggested. Did you try running just the line I provided by itself? No, The code provided by you is not working. Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
kcvinu Posted January 22, 2015 Author Posted January 22, 2015 Simplified with the Winapi UDF: #include <WinAPI.au3> $hPriorActiveWindow = _WinAPI_GetWindow(WinGetHandle("[ACTIVE]"),$GW_HWNDNEXT) WinActivate($hPriorActiveWindow) Thank you, let me try Spoiler My Contributions Glance GUI Library - A gui library based on Windows api functions. Written in Nim programming language. UDF Link Viewer --- A tool to visit the links of some most important UDFs Includer_2 ----- A tool to type the #include statement automatically Digits To Date ----- date from 3 integer values PrintList ----- prints arrays into console for testing. Alert ------ An alternative for MsgBox MousePosition ------- A simple tooltip display of mouse position GRM Helper -------- A littile tool to help writing code with GUIRegisterMsg function Access_UDF -------- An UDF for working with access database files. (.*accdb only)
MikahS Posted January 22, 2015 Posted January 22, 2015 (edited) Did you try post #12? Glad you found a solution! Edited January 22, 2015 by MikahS Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now