Jump to content

activate previous window


monte
 Share

Recommended Posts

Hello, I have a tray menu and I want to activate the window that was active before I accessed the tray menu. How do I do this, is there a z order list I can access with winactivate, or something like that? Any help would greatly be appreciated, thanks.

#include <IE.au3>
#Include <Constants.au3>
#NoTrayIcon

;;;;;;;;;
;hotkeys
;;;;;;;;;
HotKeySet("^#b", "cmd")      ;cmd prompt
HotkeySet("^#c", "copy")         ;copy

;;;;;;
;tray
;;;;;;
Opt("TrayMenuMode",1)
$cmd   = TrayCreateItem("Cmd Prompt  - Ctrl Win B")
$copy   = TrayCreateItem("Copy  - Ctrl Win C")
TrayCreateItem("")
$exititem      = TrayCreateItem("Exit")

TraySetState()
TraySetToolTip("Hotkeys")



While 1
  $msg = TrayGetMsg()
  Select
    Case $msg = 0
      ContinueLoop
    Case $msg = $exititem
      ExitLoop
    Case $msg = $cmd
      cmd()
    Case $msg = $copy
      copy()
  EndSelect
WEnd


;;;;;;
;CMD
;;;;;;
func cmd()
  TraySetState(4)
  Run(@ComSpec & " /k color 02&prompt #&cls" & @cr)
  traysetstate(8)
endfunc

;;;;;;
;Copy
;;;;;;
func copy()
 ;activate previous window and copy what's selected
 ;winactivate ????
 ;winwaitactive ???
  sleep(100)
  send("^c", 0)
  sleep(100)
  msgbox(0, "Hotkeys", "You copied:" & @cr & stringstripws(ClipGet(), 8)
endfunc
Link to comment
Share on other sites

Windows does keep track of the Z-order of previous windows. The array returned from WinList is in z-order. Based on that, I did a function called _WinPrevious(). It will let you go back 1 in the z-order by default, but can receive an integer to go back farther.

If Alt-Tab covers all your bases, then it's still overkill, of course.

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...