How do you make your alt+tab functionality work like OSX where it uses meta+tab and not alt+tab, while also respecting the shift key?
I have the solution for this. Note the date of this post because I've gone through many apparently obsolete solutions before figuring this out. I've worked on this problem for a total of about 4 hours and have encountered a plethora of solutions that don't work. I'm a professional developer of 10 years but this problem nearly killed me.
There is a special keyword to replicate Alt + Tab functionality.
I also realized that AutoHotkey will block keyboard signals until you've completed the shortcut by releasing all keys, so any additional tabs that are sent while I held down the control key are ignored.
Yes, it does that. Hotkeys create something they call "threads" and by default there can be only one. So if you want to trigger the same hotkey again before the previous "thread" has finished, you can use #MaxThreadsPerHotkey directive.
The code below swaps Alt + Tab and Ctrl + Tab functionality — that is Ctrl + Tab will switch between apps and Alt + Tab between tabs in a browser. The thread limit is 255 which means that you can hold Ctrl and (in theory) press Tab 255 times before it stops working.
#UseHook
SendMode Input
#MaxThreads 255
#MaxThreadsPerHotkey 255
<!Tab::
Send {LCtrl down}{Tab}
Keywait LAlt
Send {LCtrl up}
return
#MaxThreadsPerHotkey
<^Tab::AltTab
I think I've spent more time trying to make AHK hotkeys do what I want than they could possibly save me even if I lived to a hundred.
<#Tab::AltTab
This will remap "win + tab" to "alt tab". It also works with multiple presses of the tab key.
Note: I've mapped RControl onto my LWin key via Windows registry, so autohotkey sits on top of that.
I found many solutions that said simply
>^Tab::
Send {LAlt down}{Tab}
KeyWait RControl
Send {LAlt up}
return
The issue here is that it doesn't handle alt+tab+tab+tab to go 3 programs back.
I also realized that AutoHotKeys will block keyboard signals until you've completed the shortcut by releasing all keys, so any additional tabs that are sent while I held down the control key are ignored.
What I realized is I needed a 2nd AutoHotKeys process to force that through. It seems like a rather redundant thing to write but here's my 2nd script:
#IfWinActive "ahk_class TaskSwitcherWnd"
Tab::Send {Tab}
#IfWinActive
If you're not familiar, the #IfWinActive stuff is just to make it so that this isn't firing every time the Tab key is sent - it's only while Windows' task switcher is in focus. Ultimately, this script simply says Tab::Send {Tab}.
Then you need to tell it to also react to the shift key. Oddly, the task switcher listens for that just fine but not Tab, so we don't need to forward the Shift key in that script too.
Ultimately, my two scripts look like this:
Script 1
#IfWinNotActive ahk_class TaskSwitcherWnd
; Remap Ctrl-Tab to Alt-Tab
$>^Tab::
Send {Alt down}{Tab}
Keywait Control
Send {Alt up}
return
; Remap Ctrl-Shift-Tab to Alt-Shift-Tab
$>^+Tab::
Send {Alt down}{Shift down}{Tab}
Keywait Control
Send {Alt up}{Shift up}
return
#IfWinActive
Script 2
#IfWinActive ahk_class TaskSwitcherWnd
Tab::Send {Tab}
#IfWinActive
Run these simultaneously.
Related
I'm trying to make Ctrl+Click just simple Click on explorer with AutoHotkey.
#IfWinActive ahk_exe explorer.exe
^LButton:: LButton
;
#IfWinActive ahk_exe explorer.exe
^LButton:: Send {Ctrl Up}{LButton}
I tried these two scripts, but they didn't work.
Still, with ^LButton, I could select multiple files.
Thanks for the help.
^LButton::LButton shouldn't work, because internally the easy remapping syntax expands to a send command with {Blind}. Or more clearly said, modifiers, that are held down, are left as is.
However, ^LButton::Send, {Ctrl Up}{LButton} should be fine.
And it does work on my system as expected.
{Ctrl Up} is redundant though, since the Send command automatically releases modifiers before sending (unless in blind mode).
Maybe try this just in case:
#IfWinActive, ahk_exe explorer.exe
^LButton::SendInput, {LButton}
#IfWinActive
Also switched over to SendInput(docs) due to it being the recommended faster and more reliable send mode.
67-year-old grannie here. My 12-year-old programmable keyboard died and I will try to use AutoHotkey in its stead to do simple keyboard macros. Here's the first one I need to create. When I press F12, I want it to send these keystrokes to Audacity (but it could be any program; the keystrokes are simply shortcut keys to do specific functions):
Alt+G
S
Enter
Enter
How would I program that in AutoHotkey?
Fairly straightforward:
F12:: ;When F12 is pressed
Send !g ;Press Alt+g
Send s ;Press s
Send {Enter 2} ;Press Enter Twice
return ;End this hotkey
(Note: Anything after a semicolon is a comment)
When tested in Audacity, it properly generates a default length clip of silence, then deselects the created audio segment.
Bonus:
Add #IfWinActive ahk_exe audacity.exe to the top of the script to make the hotkey only activate if Audacity is the active window.
Might already be answered but here we go. I wanted to write an AutoRun script using AutoHotKey for DayZ. It basically consists of two keys being constantly pressed and then slept. Easy script. But I want it to do one more thing. I want to be able to shift tab in the standalone to the web browser and still autorun while browsing say, facebook. Is there any way this can be possibly done? Thanks in advance.
Would probably help if I pasted the script to make it more concise.
#NoEnv
SendMode Input
#IfWinActive, DayZ
lctrl::
Send {w Down}
Send {lshift Down}
W::Sleep
return
Super simple. Basically the only issue, as I said, is that when I use the steam overlay to shift + tab to the browser, my keypresses, and therefore, autorun macro, doesn't persist. I am not sure if there's any way to remedy this but any help would be appreciated.
Your keys don't persist because they depend on DayZ being active. When the steam overlay is active, well the game is no longer active.
Use ControlSend, to send keys to inactive windows.
See the following example:
#NoEnv
SendMode Input
lctrl::
ControlSend, , {w Down}, DayZ
ControlSend, , {lshift Down}, DayZ
W::Sleep
return
I have this script
+#^a::
SetTitleMatchMode 2
IfWinExist InterCounter
{
WinActivate
Send x
Send !{ESC}
}
return
after using it, alt stays pressed and I have to press alt on my keyboard to get to normal state (no key pressed). If I forget to do it and type something, a key shortcut is initiated. If I type SPACE for example, ALT+SPACE is pressed.
I tried various things. {Alt up} and other. They did not work. Where is the problem? Is there a fix for my script?
(would do that in a comment if I could)
try to Send , {ALT down}{ALT up} which should do the trick. If not something else is interfering, like a 3d party program. Try close everything on your system except notepad and the AHK-script and see if that helps.
So i am using this great software called Website-Watcher, which is rss feed reader and web content tracker.
I have configured it to open external links in firefox, which is opening tabs in the background.
BUT the problem is that Website-Watcher looses focus after i hit some link, so is there a way to open a link, regain lost focus and send click to be able to scroll, i have found a script that activates window on mouse scroll BUT the scroll functionality of program is not regained.
Please, give me some ideas!
EDIT UPDATE::: I have finally made it work, the problem was with the Windows 8.1 Admin rights, because i run Website-Watcher elevated, script that i was using stopped working.
The scripts are here:
http://www.autohotkey.com/board/topic/6292-send-mouse-scrolls-to-window-under-mouse/
http://www.autohotkey.com/board/topic/99405-hoverscroll-verticalhorizontal-scroll-without-focus-scrollwheel-acceleration/?p=623967
With those scripts you can perform scroll without activating windows or if you use the former you can even activate windows with mouse scroll.
Use WinActivate
For example, WinActivate Untitled - Notepad would activate (bring focus to) the window "Untitled - Notepad". This title must be exact and is case-sensitive.
It might be easiest to do this in a low-tech way. I'm not familiar with Website-Watcher, so I'll share a script I use that you should be able to adapt.
I use Feedly in Chrome for RSS reading, and hitting "v" in Feedly opens the story in a new tab. I use my Media Play button to hit "v" and bring me back to Feedly:
Media_Play_Pause::
send v
sleep 50
send {Ctrl Down}{Shift Down}{Tab}{Shift Up}{Ctrl Up}
return
So, define your hotkey, have it trigger the link to open in Firefox, and then hit Alt-Tab to jump back:
X::
send y
sleep 50
send {Alt Down}{Tab}{Alt Up}
return
Obviously, replace "X" and "y" above.
I don't care about using my Media Play button for anything else, but if you want your hotkey to be context sensitive, use #IfWinActive.
Use "WinGet, variableName , List, yourWindowName" (without quote)
then call your variableName contate it with 1 in every ControlSend
for example :
WinGet, nexid, List, myHyperTerminal
ControlSend, , {shift down}at=cmgs{shift up}=303{ENTER}, ahk_id %nexid1%
sleep, 1000
ControlSend, , {shift down}sms{shift up}{space}10000, ahk_id %nexid1%
sleep, 1000
if you want to use control key such as shift, ctrl, alt, don't forget to add "SetKeyDelay, intDelay, intPressDuration" (without quote)
for example the script will be list this
#usehook on
SetKeyDelay, 50, 20
WinGet, nexid, List, zz1
$F6::
ControlSend, , {shift down}at=cmgs{shift up}=303{ENTER}, ahk_id %nexid1%
sleep, 1000
ControlSend, , {shift down}sms{shift up}{space}10000, ahk_id %nexid1%
sleep, 1000
return
$F7::pause
it will be sent to active/inactive window "zz1" as :
AT+CMGS=303
SMS 10000