FULLY WORKING ALT TAB WIN 8

Post your working scripts, libraries and tools
MasterMind420
Posts: 15
Joined: 17 Nov 2015, 16:19

FULLY WORKING ALT TAB WIN 8

17 Nov 2015, 20:50

This was very difficult to troubleshoot but I finally got it working properly...enjoy :-) If you compile the script Run As Admin or it will malfunction...I was prompted to find this workaround because all other methods I found either required too much hackish work or didn't work exactly how ALT TAB should...

Code: Select all

SetTimer, fix, 100
	
!SHIFT::
	Send, !{Tab} ;Fixes displaying an empty Alt Tab Menu.
	run, C:\Users\Default\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\Window Switcher.lnk ;Opens Alt Tab Menu.
Return

fix: ;Fixes enter when releasing the modifier key.
	WinWaitActive, Task Switching ;Fixes spamming the enter key which is a side effect if anything else is used.
	KeyWait, LAlt,
	SendInput, {Enter}
Return
Last edited by MasterMind420 on 06 Dec 2015, 11:44, edited 10 times in total.
wolf_II
Posts: 2687
Joined: 08 Feb 2015, 20:55

Re: FULLY WORKING ALT TAB WIN 8

17 Nov 2015, 21:29

I'm trying to get to the bottom of the "fire enter at random" issue.

First: may I ask if you get any different behaviour with the following change to the fix: routine?

Code: Select all

fix: ; Allow enter when releasing the modifier key.
    WinWaitActive, Task Switching ; This prevents spamming the enter key which is a side effect in notepad.
    KeyWait, LAlt
    SendInput, {Enter}
Return
I wonder if the { or } are needed?
I wonder if the #IfWinActive is doing anything?

I don't have Win8, so I can't test.
MasterMind420
Posts: 15
Joined: 17 Nov 2015, 16:19

Re: FULLY WORKING ALT TAB WIN 8

17 Nov 2015, 21:55

strangely enough your right there not needed, I think i may have left them in thinking they fixed something, WinWaitActive does the job as it should :) Also the brackets aren't necessary at all, it's just how I code hotkeys and timers out of habit...I edited the post to reflect the changes, thanks.
MasterMind420
Posts: 15
Joined: 17 Nov 2015, 16:19

Re: FULLY WORKING ALT TAB WIN 8

17 Nov 2015, 22:01

Ok so no change if i compile the script, it seems to work fine and then one of the times I hit shift to tab through the windows it just closes as if enter was hit...sometimes i can hit shift over and over no problems, it just happens out of nowhere...uncompiled it works fine...also i'm curious to know what would cause hotkeys to not work in a compiled script...I have another script that works fine until compiled, the script is an osd i made however all hotkeys i put into the script don't work after that...I know certain directives can cause compiled scripts to function differently...but i don't think thats the case with this or my other script...
lexikos
Posts: 6591
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: FULLY WORKING ALT TAB WIN 8

17 Nov 2015, 22:16

Do not put a hotkey (even a one-line hotkey) inside another hotkey subroutine. Luckily in this case it doesn't matter; the !SHIFT sub encounters the Enter sub's Return instead of its own, but the end result is the same.

Your timer does not run every 100ms. It runs after 100ms, then waits (possibly indefinitely) for the window to be active, then for the LAlt key to be released. If the timer interrupted the !SHIFT hotkey, the hotkey will not work while the timer sub is waiting. Possible workarounds include replacing WinWaitActive/KeyWait with IfWinActive/GetKeyState, or #MaxThreadsPerHotkey 2.

Your fix subroutine will not necessarily send Enter to the Alt-Tab window. Normally the window disappears when you release Alt, and your sub waits for Alt to be released before sending Enter. Ctrl-Alt-Tab opens the task switcher and keeps it open after you release Alt.

I have added code tags to your post. For reference, you can quote or edit your post to see how code tags are written. Or you can use the Code button in the full editor, or the "Select code" drop-down.
MasterMind420
Posts: 15
Joined: 17 Nov 2015, 16:19

Re: FULLY WORKING ALT TAB WIN 8

17 Nov 2015, 23:30

Awesome advice...thankyou so much for your input and time, very well explained...however, i just tried what you told me and either the Alt Tab Menu would tab in the wrong direction Left instead of Right using #MaxThreadsPerHotkey 2 or using getkeystate, U, LAlt and IfWinActive, Task Switching caused the enter key to fire indefinately outside of the Task Switching window, very strange you'd think it would enforce the window. I've been having a hell of a time with this because even though what i've tried makes perfect sense, it has undesired results...the code i've posted is working fine non compiled, exactly how Alt Tab should work. I moved the Enter::Return outside & above the !SHIFT hotkey and it still seems to work fine, however compiled it still randomly sends enter to the task switching window, uncompiled it does not...

Edit- I just tested the compiled .exe as an admin and it works as expected, I didn't think to do that because normally I don't have to, and my UAC is disabled...So I corrected the code above and as is it works now...Thankyou again for all your help...
MasterMind420
Posts: 15
Joined: 17 Nov 2015, 16:19

Re: FULLY WORKING ALT TAB WIN 8

21 Nov 2015, 18:27

This will add OS detection to the script...It's only been tested on Win 8 and 10 though.

Code: Select all

i := GetOSVersion()
If (i = 6.3)
    SetTimer, fix, 100

	fix: ;Fixes enter when releasing the modifier key.
		WinWaitActive, Task Switching ;Fixes spamming the enter key which is a side effect if anything else is used.
		KeyWait, LAlt,
		SendInput, {Enter}
		Return
		
#If (i = 6.3)		
	!SHIFT::
		Send, !{Tab} ;Fixes displaying an empty Alt Tab Menu.
		run, C:\Users\Default\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\Window Switcher.lnk ;Opens Alt Tab Menu.
	Return
#If

#If (i <> 6.3)
    !SHIFT::Tab
#If

GetOSVersion()
	{
    Return ((r := DllCall("GetVersion") & 0xFFFF) & 0xFF) "." (r >> 8)
	}
Last edited by MasterMind420 on 21 Nov 2015, 23:35, edited 1 time in total.
lexikos
Posts: 6591
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: FULLY WORKING ALT TAB WIN 8

21 Nov 2015, 19:26

Now that I'm back on my Windows 10 system (which I presumed would have the same issues as Windows 8, but maybe not), I'm curious as to what it is that your script is supposed to do.

!SHIFT::SendInput, {LAlt Down}{Tab} initially worked just fine for me without additional workarounds.

When re-tested (with only this line), the hotkey recursively invoked itself and activated Alt+Tab several times in an instant. It just depends on whether !SHIFT is implemented with the "reg" method or the "k-hook" method (see ListHotkeys). The "reg" method allows this recursion. In the context of your script, #If requires the "k-hook" method to be used. For other cases, one can use $ to force the "k-hook" method:

Code: Select all

$!Shift::SendInput, {LAlt Down}{Tab}
As for the Enter hotkey which "Fixes the Alt Tab Menu from closing after first use", it made no difference whatsoever. Seems like nonsense to me. The only effect this hotkey should have is to prevent anything from happening when you press Enter while not holding Alt. The Alt Tab menu still disappears when I release Alt, as expected, so the hotkey is pretty useless.

In the absence of any other reason to install the keyboard hook (such as $ or #If), adding any #IfWinActive hotkey to the script may cause the keyboard hook to be installed. This may indirectly affect the behaviour of some hotkeys and functions, since the hook is better able to track key state. But since your current script requires the hook anyway (due to #If), the Enter hotkey does not even have this effect.

When I tried without If (i = 6.3) (since I'm on 10.0, not 6.3), the timer did exactly what I warned about earlier:
I wrote:Your fix subroutine will not necessarily send Enter to the Alt-Tab window. Normally the window disappears when you release Alt, and your sub waits for Alt to be released before sending Enter.
It reliably sent Enter to the newly activated window, not the Alt-Tab menu.

Note that because you're already holding Alt when you activate !SHIFT, {LAlt down} is redundant. It also causes the hotkey to misbehave if I use RAlt+RShift, though I'm not really sure how. By contrast, $!Shift::SendInput, {Blind}{Tab} doesn't send a redundant Alt keystroke and works just fine for me with both Alts and both Shifts.

In fact, !Shift::Tab also works. :lol:
MasterMind420
Posts: 15
Joined: 17 Nov 2015, 16:19

Re: FULLY WORKING ALT TAB WIN 8

21 Nov 2015, 23:31

Thankyou for the input, strangely enough the other day when I tested the fix on Win 8 it required me to use...

Code: Select all

#IfWinActive, Task Switching
	Enter::Return ;Fixes the Alt Tab Menu from closing after first use.
#IfWinActive
However now it seems to work without it...Just releasing Alt doesn't activate the selected window as you'd expect so the fix is required on win 8...you would think releasing Alt would activate it...I'll test more in the morning, i've edited the script to reflect your findings...

Edit: Ok so I may have spoken too hastely, Running the script for the first time, after releasing Shift the menu immediately activates the selected window while still holding Alt, releasing and hitting Alt Shift again the menu acts normally...until reloading the script again. This is frustrating...I will be switching to a fresh install of win 8 tomorrow to test if it still happens...you said its not necessary and i witnessed it myself after loading the script fresh without it earlier, it worked fine. So i'm almost wondering if my Win 8 install is acting up somehow...Also as far as Win 10 is concerned it's not the same case as Win 8...Windows 10 works as expected with just !SHIFT::Tab, using the fix on windows 10 only causes the Alt Tab Menu to malfunction, not tabbing properly...using it on Win 8 it works as expected...

So my above code definately fixes an issue with it or my Win 8 install is screwy, either way i'll narrow it down...
MasterMind420
Posts: 15
Joined: 17 Nov 2015, 16:19

Re: FULLY WORKING ALT TAB WIN 8

22 Nov 2015, 10:36

Ok now that I better understand what you were saying lexikos...#UseHook does fix the problem...thanks for your help...
User avatar
KuroiLight
Posts: 327
Joined: 12 Apr 2015, 20:24
GitHub: KuroiLight

Re: FULLY WORKING ALT TAB WIN 8

23 Nov 2015, 05:53

original post
Edit: after googling I see this is a common issue, nvm me then.
Windows 10, Ryzen 1600, 16GB G.Skill DDR4, 8GB RX 480 | [MyScripts][MySublimeSettings] [Unlicense][MIT License]
01/24/18
[/color]
Philister
Posts: 2
Joined: 01 Apr 2016, 07:31

Re: FULLY WORKING ALT TAB WIN 8

27 Sep 2016, 15:39

If anyone just wants a "toggle back and forth between two windows" hotkey that works on Windows 10 (and maybe 8 as well?), I found that you can use:

Code: Select all

		Send #{Tab}
		Sleep 75
		Send {Right}{Enter}
It produces some ugly window animations, but works great as a simple hack to work around the UI problem otherwise.
Acecool
Posts: 37
Joined: 10 Jan 2016, 18:25
Facebook: Acecool
Google: Acecool
GitHub: Acecool
Contact:

Re: FULLY WORKING ALT TAB WIN 8

15 Dec 2016, 05:16

Honestly this is a hack to use a timer to check on a key...

Here's how I do the Windows 10 Task View / Virtual-Desktop Page - I prefer this over alt tab... I also use CapsLock instead..

Oh, if you want a framework which will automatically include / load new hotkeys ( just drag and drop files into the folders and run AutoHotkey.exe - You can use Reload This Script if you change an existing script but need to re-execute to re-generate the load-order file when new ones are added ) - can also automatically run stand-alone scripts each time it is executed.

https://bitbucket.org/Acecool/acecoolah ... k/overview

This is the hotkey in question: https://bitbucket.org/Acecool/acecoolah ... _win10.ahk
-Josh 'Acecool' Moser
I teach various programming languages, game programming, etc... I am also taking on programming jobs as my health allows.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: Bing [Bot], tmplinshi and 57 guests