Taskbar icon click to keep that window on top?

Get help with using AutoHotkey and its commands and hotkeys
PotentialUser

Taskbar icon click to keep that window on top?

30 Jan 2014, 23:40

I have a real problem with windows stealing focus on me when I am jumping around to different windows in WIN7. I came across this link:

http://webserver.computoredge.com/onlin ... ista&src=5

Which showed me this autokey script line: ^#8::WinSet, AlwaysOnTop, toggle, A

For a new user like me is there a fairly easy way to make this alwayontop make the window icon I click on in the task bar be the ONLY (that is turn off any another window on top if needed) and make it the window always on top?

Thanks in advance!
Zelio
Posts: 275
Joined: 30 Sep 2013, 00:45
Location: France

Re: Taskbar icon click to keep that window on top?

31 Jan 2014, 03:37

Hello, I am not sure to understand, something like this ?

Code: Select all

~h:: ;press H to hide your window and your icon
myHwnd := WinExist("A") ; get the id of the current active window, for futur use
WinHide, ahk_id %myHwnd% ; hide the window, must to be done for a dynamic style change without bug
WinSet, ExStyle, +0x80, ahk_id %myHwnd% ; to set WS_EX_TOOLWINDOW will disable the taskbar icon and do other graphic style (border,  title, ...)
return

~s:: ; press S to show your last hidden window
WinShow, ahk_id %myHwnd% ; show the window
WinSet, AlwaysOnTop, toggle, ahk_id %myHwnd% ; and this will be always on top
return
also from manual, to get all windows

Code: Select all

WinGet, id, list,,, Program Manager
Loop, %id%
{
    this_id := id%A_Index%
    WinActivate, ahk_id %this_id%
    WinGetClass, this_class, ahk_id %this_id%
    WinGetTitle, this_title, ahk_id %this_id%
    MsgBox, 4, , Visiting All Windows`n%a_index% of %id%`nahk_id %this_id%`nahk_class %this_class%`n%this_title%`n`nContinue?
    IfMsgBox, NO, break
}
jpginc
Posts: 123
Joined: 29 Sep 2013, 22:35

Re: Taskbar icon click to keep that window on top?

31 Jan 2014, 03:38

I'm not sure how to get an item that was clicked in the task bar...but this hotkey makes only one window always on top

Code: Select all

onTopWindow := ""

return
^#8::
{	if(onTopWindow)
	{	WinSet, AlwaysOnTop, Off, % onTopWindow
		oldWindow := onTopWindow
		onTopWindow := "ahk_id " WinExist("A") ;get the unique id of the active window
		if(oldWindow == onTopWindow) 
		{	;if the active window was already the "on top" window then don't make
			;it the on top window again
			onTopWindow := ""
			return
		}
		WinSet, AlwaysOnTop, On, % onTopWindow
	} else
	{	onTopWindow := "ahk_id " WinExist("A")
		WinSet, AlwaysOnTop, On, % onTopWindow
	}
	return
}
User avatar
dmg
Posts: 254
Joined: 02 Oct 2013, 01:43
Location: "Twelve days north of Hopeless and a few degrees south of Freezing to Death"
Contact:

Re: Taskbar icon click to keep that window on top?

31 Jan 2014, 03:55

What you are asking is certainly possible, but it would be harder than it sounds. It may not be as convenient but you may be better served by using a simpler always on top script. I wrote this app in AutoHotkey:
http://crzyinc.weebly.com/stick-it.html
It works quite well, though not quite how you asked. The source code is included so you can modify it to suit your needs.
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion
------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
PotentialUser

Re: Taskbar icon click to keep that window on top?

31 Jan 2014, 17:20

Well thanks for the tips! It doesn't seem easy. I will see what I can piece together in my spare time. Now I have three freeware always on top programs. When I use stickit on a window it interestingly changes the unpin icon and shakes(aeroshake) the window. These are the features from the other two programs needed to toggle the window on top function.

I'd really like windows(win7) just to work like it should/used to and keep the current window in focus and on top until I select(with my pointer) otherwise. My suggested solution seems to be the easiest solution for me to use if I can get it done.
PotentialUser

Re: Taskbar icon click to keep that window on top?

03 Feb 2014, 19:24

After thinking about it for awhile I thought I could start with using JPGINC's example but make it turn off all AlwaysOnTopWindows and make the active window AlwaysOnTop, with a hotkey.

The problem is JPGINC's code doesn't work as noted when I tried it. I think it needs a loop of some sort, maybe within Zelio's GetAllWindows example?? It has a return in it, is the loop statement just missing?

I don't know enough about the AutoKey script syntax at this time to know.
User avatar
dmg
Posts: 254
Joined: 02 Oct 2013, 01:43
Location: "Twelve days north of Hopeless and a few degrees south of Freezing to Death"
Contact:

Re: Taskbar icon click to keep that window on top?

03 Feb 2014, 19:34

So, at this point you would like code to remove the always on top attribute from all open windows, then make only the currently active window always on top, using the Ctrl-Win-8 hotkey? I can do that! Check back in a day or so for the code...
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion
------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
User avatar
dmg
Posts: 254
Joined: 02 Oct 2013, 01:43
Location: "Twelve days north of Hopeless and a few degrees south of Freezing to Death"
Contact:

Re: Taskbar icon click to keep that window on top?

03 Feb 2014, 20:08

This appears to work but may need some tinkering:

Code: Select all

^#8::
 {
   winget, win_, list
   loop, % win_
    {
      winget, process, processname, % "ahk_id" win_%a_index%
      wingetclass, class, % "ahk_id" win_%a_index%
      if (process = "explorer.exe" && class = "Progman") || (process = "explorer.exe" && class = "Shell_TrayWnd")
       {
         continue
       }
      else
       {
         winset, alwaysontop, off, % "ahk_id" win_%a_index%
       }
    }
   winset, alwaysontop, on, a
 }
return
Hitting the hotkey should remove always on top from all open windows, then make the active window always on top. It seems to work in my limited testing. It has some code to prevent attempting to operate on the desktop or task bar. I don't know if that is needed, but most of this code is from another script and I decided to leave that part in. :ugeek:
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion
------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
PotentialUser

Re: Taskbar icon click to keep that window on top?

03 Feb 2014, 22:44

Hmmpfh! I'm stumped as dmg's code doesn't do anything for me either. THANKS by the way as that is what I was trying to do.

After starting it I tried a OPEN and it says 005 lines have been executed, 006 when I put a #Warn in the beginning.

I went back to using Notepad to edit as the help said something about old script on 1.0 versus 1.1 and the correct UTF/ANSI format. I'm on Version v1.1.14.02 using Win7 SP1.

I will keep at it for a bit but I'm not sure why nothing happens for me. The only thing I noticed running either script was the first time it was ran, when I hit the key sequence(Ctrl 8) a different window will come forward then was active. It only does this once though.
PotentialUser

Re: Taskbar icon click to keep that window on top?

03 Feb 2014, 22:54

With the ListVars command I get:

Global Variables (alphabetical)
--------------------------------------------------
0[1 of 3]: 0
class[0 of 0]:
ErrorLevel[1 of 3]: 0
process[0 of 0]:
win_[0 of 0]:
-----------------------------------------
Then if I view: lines most recently executed I get:

Script lines most recently executed (oldest first). Press [F5] to refresh. The seconds elapsed between a line and the one after it is in parentheses to the right (if not 0). The bottommost line's elapsed time is the number of seconds since it executed.

---- C:\Users\Wildbill2\Wildbill1\Documents\AutoKey\OneWindowOnTop.ahk
004: ListVars (0.05)
006: Return (58.58)

Press [F5] to refresh.
-----------------------------------------

So that makes me believe that it is not executing any of the code in between for some reason.
User avatar
dmg
Posts: 254
Joined: 02 Oct 2013, 01:43
Location: "Twelve days north of Hopeless and a few degrees south of Freezing to Death"
Contact:

Re: Taskbar icon click to keep that window on top?

03 Feb 2014, 23:04

Hmm... If I run the code I posted and look at the lines executed I see "Return". That is because a hotkey is considered the end of the auto-execute section. No other code should run until you press the hotkey to run the code. Try running the code exactly as I posted it, then press the hotkey, then double click on the tray icon. That should show executed lines without the need for listlines.

Assuming the code is executing correctly, I think the problem may be user credentials. Autohotkey may not be able to operate on windows unless you run as administrator. It may be worth looking into.
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion
------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
Potential

Re: Taskbar icon click to keep that window on top?

03 Feb 2014, 23:11

Oh Yeah, when I run the sample AutoHotkey.ahk script included with the program it works fine; essentially w/o all the comments:

#z::Run www.autohotkey.com

^!n::
IfWinExist Untitled - Notepad
WinActivate
else
Run Notepad
return
User avatar
dmg
Posts: 254
Joined: 02 Oct 2013, 01:43
Location: "Twelve days north of Hopeless and a few degrees south of Freezing to Death"
Contact:

Re: Taskbar icon click to keep that window on top?

04 Feb 2014, 02:02

OK. So you are saying... ? That since the example script uses WinActivate it does not need to be run as admin? I am not sure I understand. Try this:

Code: Select all

^#8::
 {
   winset, alwaysontop, toggle, a
 }
return
Does this hotkey make the active window always on top/not always on top? If it works then the problem is not your user privileges. Unfortunately that would mean I have no idea what the problem actually is.
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion
------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
PotentialUser

Re: Taskbar icon click to keep that window on top?

04 Feb 2014, 02:20

Ah OK, my bad as it was something very simple that I missed. All the scripts work. I just didn't realize that ^#8 is Control Win 8. I was just doing Control 8. I do swear that I tried the full Control Win 8 before and it didn't work. I presume I can just use Control 8 = ^8, without the windows button as that's what I prefer.

At any rate I tried the your other script and it works though overall it's not doing what I hoped. I have to minimize that window to get to another. Now when I have to other window on top and hit the hotkey it just makes that window also on top but doesn't undo the other one because it's minimized.

I will have to play with it more tomorrow.

Thanks for the help! :)
User avatar
dmg
Posts: 254
Joined: 02 Oct 2013, 01:43
Location: "Twelve days north of Hopeless and a few degrees south of Freezing to Death"
Contact:

Re: Taskbar icon click to keep that window on top?

04 Feb 2014, 02:25

The code I posted here:
http://ahkscript.org/boards/viewtopic.p ... 027#p11027
Makes all open windows NOT always on top whether they are minimized or not. It works on my Win XP system. Is that the code you are talking about?
"My dear Mr Gyrth, I am never more serious than when I am joking."
~Albert Campion
------------------------------------------------------------------------
Website | Demo scripts | Blog | External contact
PotentialUser

Re: Taskbar icon click to keep that window on top?

04 Feb 2014, 16:36

That was the code I was talking about. I tried it again today and for the most part it works. Seems to work most of the time but the first time the hotkey is executed it doesn't always work. Also when I raise a window from the taskbar, sometimes I have to still click on it in order for the hotkey to work.

I will play with it a bit and think about how I can make it closer to what I want(how windows used to/should work).

Thanks again!
PotentialUser

Re: Taskbar icon click to keep that window on top?

04 Feb 2014, 22:22

A slight modification to DMG's code pretty much gets what I need. The delay is probably not the best way to go but it works. Overall it works most of the time but not all the time.

[code]
~^Lbutton::
{
sleep 1500
winget, win_, list
loop, % win_
{
winget, process, processname, % "ahk_id" win_%a_index%
wingetclass, class, % "ahk_id" win_%a_index%
if (process = "explorer.exe" && class = "Progman") || (process = "explorer.exe" && class = "Shell_TrayWnd")
{
continue
}
else
{
winset, alwaysontop, off, % "ahk_id" win_%a_index%
}
}
winset, alwaysontop, on, a
}
return
[code]
PotentialUser

Re: Taskbar icon click to keep that window on top?

08 Feb 2014, 07:32

I have been trying to identify only the taskbar icons/tabs. The previous if code from DMG to identify the taskbar doesn't work in Win7. Thus I was able to chop it out and get the reduced code below:

[code]
~^Lbutton::
{
sleep 1500
winget, win_, list

loop, % win_
{
winget, process, processname, % "ahk_id" win_%a_index%
winset, alwaysontop, off, % "ahk_id" win_%a_index%
}
winset, alwaysontop, on, a
}
return
[/code]

Does anyone know how to get this key sequence to only work on taskbar icons/tabs in Win7? Should I start another topic? I used a Msgbox to output the class and such but nothing seems unique to the taskbar.
PotentialUser

Re: Taskbar icon click to keep that window on top?

10 Feb 2014, 12:30

I messed up my left touchpad and mouse, button now. I removed the ^/control and used just ~Lbutton::

I tried it out and was doing control left touchpad as well to try and bring other windows forward to see if the window was really on top or not.

Now my left touchpad button sticks on sometimes. The same exact behavior occurs if I use a USB mouse. A restore to the last time I did a windows defender update keeps failing. It's probably something in the registry but I'm very leary of messing with that.

Has anybody else figured out how to fix problems like this??

Thanks in advance!
PotentialUser

Re: Taskbar icon click to keep that window on top?

11 Feb 2014, 05:17

Well it's was just a sticky touchpad key :| What threw me is the USB mouse that I grabbed also had a bad left mouse button; what was the odds of that?

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], dd900, flyingDman, Google [Bot] and 95 guests