BetterDesktopTool and Autohotkey - autohotkey

I have setup a keyboard shortcut in BetterDesktopTool that has a sort of mission control view for Windows.
The shortcut is Alt + Tab and I want to map my F3 key to that. But it won't work in Autohotkey
#InstallKeybdHook
#SingleInstance force
SetTitleMatchMode 2
#Include Apple Wired Keyboard.ahk
SendMode Input
; --------------------------------------------------------------
; NOTES
; --------------------------------------------------------------
; ! = ALT
; ^ = CTRL
; + = SHIFT
; # = WIN
; media/function keys all mapped to the right option key
F7::SendInput {Media_Prev}
F8::SendInput {Media_Play_Pause}
F9::SendInput {Media_Next}F3F3
; F10::SendInput {Volume_Mute}
; F11::SendInput {Volume_Down}
; F12::SendInput {Volume_Up}
; swap left command/windows key with left alt
LWin::LAlt
LAlt::LWin
; Misc.
F20::WinMinimize A
*F3::SendInput {Alt}{Tab}
; F13-15, Volume
F13::SendInput {Volume_Mute}
F14::SendInput {Volume_Down}F3F3
F15::SendInput {Volume_Up}
;F16-19 Standerd
F16::SendInput {PrintScreen}
F17::SendInput {ScrollLock}
F18::SendInput {Pause}
F19::Run wmplayer
I know that my Alt + Tab shortcut works, but it doesn't activate the hotkey for BetterDesktop

Have a look at this documentation:
http://www.autohotkey.com/docs/Hotkeys.htm
Search for "Substitutes for Alt-Tab"

Related

Remap `AltGr & someKey`

How do I remap e.g. AltGr + i?
I know how to remap other combinations like alt + i (!i::Send, test) or shift + i (+i::Send, test). But this doesn't work for AltGr.
I know how to map AltGr isolated: LControl & RAlt::Send, test works. But LControl & RAlt & i::Send, test doesn't work.
So, how do I go about it?
EDIT: SOLVED
This solution worked
From the post that OP linked:
Use a context sensitive #IF statement to check whether AltGr is held down, then create a standard one-button hotkey.
#user3419297's example:
LControl & RAlt:: AltGr := true ; assign the boolean value "true" to the variable 'AltGr''
LControl & RAlt Up:: AltGr := false
; The #If directive creates context-sensitive hotkeys and hotstrings
#If (AltGr) ; If this variable has the value "true"
a:: MsgBox AltGr+a
a & b:: MsgBox AltGr+a+b
b & a:: MsgBox AltGr+b+a
h & l:: Send Hello
i & e:: Run iexplore.exe
n & p:: Run notepad
w & p:: Run wordpad
#If ; turn off context sensitivity
So for OP's specific question:
#If (AltGr)
i::Send, test
#If
More info: Context Sensative #IF statements

What is the right way to send Alt + Tab in Ahk?

Ok. I know this is a very stupid question.
But I'm stuck already for an hour.
I got very little experience with ahk, however I made work every script until now with no problems. I explored the ahk tutorials but found no solution up to now.
I'm trying to switch to prev. app with a single numpad off key.
I've tried:
!{Tab}
,
{Alt down}{Tab}{Alt up}
I've tried it with Sleep delays, multiline, multiline inside brackets, with and without commas after commands, etc.
I'm quite sure is very simple but something I've not tried yet.
Any suggestion?
$F1:: AltTab()
$F2:: AltTabMenu()
; AltTab-replacement for Windows 8:
AltTab(){
list := ""
WinGet, id, list
Loop, %id%
{
this_ID := id%A_Index%
IfWinActive, ahk_id %this_ID%
continue
WinGetTitle, title, ahk_id %this_ID%
If (title = "")
continue
If (!IsWindow(WinExist("ahk_id" . this_ID)))
continue
WinActivate, ahk_id %this_ID%
WinWaitActive, ahk_id %this_ID%,,2
break
}
}
; AltTabMenu-replacement for Windows 8:
AltTabMenu(){
list := ""
Menu, windows, Add
Menu, windows, deleteAll
WinGet, id, list
Loop, %id%
{
this_ID := id%A_Index%
WinGetTitle, title, ahk_id %this_ID%
If (title = "")
continue
If (!IsWindow(WinExist("ahk_id" . this_ID)))
continue
Menu, windows, Add, %title%, ActivateTitle
WinGet, Path, ProcessPath, ahk_id %this_ID%
Try
Menu, windows, Icon, %title%, %Path%,, 0
Catch
Menu, windows, Icon, %title%, %A_WinDir%\System32\SHELL32.dll, 3, 0
}
CoordMode, Mouse, Screen
MouseMove, (0.4*A_ScreenWidth), (0.35*A_ScreenHeight)
CoordMode, Menu, Screen
Xm := (0.25*A_ScreenWidth)
Ym := (0.25*A_ScreenHeight)
Menu, windows, Show, %Xm%, %Ym%
}
ActivateTitle:
SetTitleMatchMode 3
WinActivate, %A_ThisMenuItem%
return
;-----------------------------------------------------------------
; Check whether the target window is activation target
;-----------------------------------------------------------------
IsWindow(hWnd){
WinGet, dwStyle, Style, ahk_id %hWnd%
if ((dwStyle&0x08000000) || !(dwStyle&0x10000000)) {
return false
}
WinGet, dwExStyle, ExStyle, ahk_id %hWnd%
if (dwExStyle & 0x00000080) {
return false
}
WinGetClass, szClass, ahk_id %hWnd%
if (szClass = "TApplication") {
return false
}
return true
}
EDIT (suggested by the user Ooker):
The script pops up a menu for you to choose.
This is what it looks like:
If you just want to switch back to the previous application, use Send, !{Esc}
You shouldn't manually send alt+tab as it is a special windows command, rather use the AltTab commands that do that for you.
AltTabMenu opens the tab menu and selects the program, whileAltTab, ShiftAltTab navigate through it.
h::AltTabMenu
n::AltTab
m::ShiftAltTab
There are some issues with Windows 8/10 and keys like ctrl-alt-del and alt-tab. Here is one solution:
F1::
{
Send {Alt Down}{Tab} ;Bring up switcher immediately
KeyWait, F1, T.5 ; Go to next window; wait .5s before looping
if (Errorlevel)
{
While ( GetKeyState( "F1","P" ) ) {
Send {Tab}
Sleep, 400 ; wait 400ms before going to next window
}
}
Send {Alt Up} ;Close switcher on hotkey release
}
return
My personal goal was to remap Alt-Tab to Win-Tab (because I'm using a Mac keyboard on a Windows 10) so I took what Stepan wrote above plus some documentation and here is is, working fine for me :
#Tab::
{
Send {LAlt Down}{Tab}
KeyWait, LWin ; Wait to release left Win key
Send {LAlt Up} ; Close switcher on hotkey release
}
return
Worked for me:
F1::
Send, {ALT DOWN}{TAB}{ALT UP}
return
It simulates the Alt + Tab behavior for F1 key.
Well, finally I found the reason and some "solutions" here and here.
It seems that Windows 8 blocks Ahk {Alt Down}{Tab} and AltTabMenu and some other keys.
For now I'm using this to scroll windows forward:
Send !{ESC}
This to display the AltTabMenu:
Run, "C:\Users\Default\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\Window Switcher.lnk"
And this to switch to the previous app as suggested in one of the topics:
LCtrl & z:: ; AltTabMenu
state := GetKeyState("Capslock", "T")
if state = 1
SetCapsLockState, Off ; CapsLock On blocks Task Switching metro window
Send, !{Tab} ; prevents displaying inactive Task Switching metro window
run, Window Switcher.lnk ; must be in script directory otherwise include path
WinWait, Task Switching,, 2
KeyWait, Ctrl
Send, {Enter}
if state = 1
SetCapsLockState, On ; restores CapsLock State
state =
return
#IfWinActive, Task Switching
LCtrl & q::Send, {Right}
LCtrl & a::Send, {Left}
It would be great to get to the previous app with no AltTabMenu splashing.
In case you want to do multiple "tabs", then the below function should help doing that. This was at least own solution on my Windows 8.1 machine.
The approach is:
1) Get a list of all the windows
2) Loop 1:
find the index of the current window
set the index to switch to ("current" + "offset")
3) Loop 2:
loop until you hit the index to switch to, then switch window
AutoHotKey code sample below:
; Test switch of 1 window
F1::AltTabFunction(offset:=1)
; Test switch of 2 windows
F2::AltTabFunction(offset:=2)
AltTabFunction(offset:=1)
{
; ****************************
; Function for switching windows by ALT-TAB (offset = number of windows to "tab")
; ****************************
; Get list of all windows.
WinGet, AllWinsHwnd, List
WinGetTitle, active_title, A ; Get title of active window.
; Find index of the current window.
counter_of_none_hidden_windows := 0 ; Initiate counter for counting only the none-hidden windows.
Loop, % AllWinsHwnd
{
; Find title for window in this loop.
WinGetTitle, CurrentWinTitle, % "ahk_id " AllWinsHwnd%A_Index%
; From [1]: "Retrieves an 8-digit hexadecimal number representing the extended style of a window.".
; [1] : https://autohotkey.com/docs/commands/WinGet.htm
WinGet, exStyle, exStyle, % "ahk_id" AllWinsHwnd%A_Index%
; Skip hidden windows by checking exStyle.
If !(exStyle & 0x100){
Continue
}
; Window is not hidden. Increase counter.
counter_of_none_hidden_windows := counter_of_none_hidden_windows+1
; Set flag.
titles_match := CurrentWinTitle = active_title
If (titles_match) {
window_index_to_switch_to := counter_of_none_hidden_windows+offset
break
}
}
; Find index of the window to switch to and do the actual switch
counter_of_none_hidden_windows := 0 ; Initiate counter for counting only the none-hidden windows.
Loop, % AllWinsHwnd
{
; From [1]: "Retrieves an 8-digit hexadecimal number representing the extended style of a window.".
; [1] : https://autohotkey.com/docs/commands/WinGet.htm
WinGet, exStyle, exStyle, % "ahk_id" AllWinsHwnd%A_Index%
; Skip hidden windows by checking exStyle.
If !(exStyle & 0x100){
Continue
}
; Window is not hidden. Increase counter.
counter_of_none_hidden_windows := counter_of_none_hidden_windows+1
; Set flag.
found_window_to_switch_to := counter_of_none_hidden_windows = window_index_to_switch_to
; Switch window.
If (found_window_to_switch_to) {
; Get title.
WinGetTitle, CurrentWinTitle, % "ahk_id " AllWinsHwnd%A_Index%
; Activate by title.
WinActivate, %CurrentWinTitle%
; Stop loop.
break
}
}
return ; Nothing to return
}
send {Alt down}{tab}
send {Alt up}
!{Tab} works to switch between windows if you add sleep before and after it.
Sleep 100
Send !{Tab}
Sleep 100
Please refer to this link: https://www.autohotkey.com/docs/Hotkeys.htm#alttab
To cancel the Alt-Tab menu without activating the selected window, press or send Esc. In the following example, you would hold the left Ctrl and press CapsLock to display the menu and advance forward in it. Then you would release the left Ctrl to activate the selected window, or press the mouse wheel to cancel. Define the AltTabWindow window group as shown below before running this example.
LCtrl & CapsLock::AltTab
#IfWinExist ahk_group AltTabWindow ; Indicates that the alt-tab menu is present on the screen.
MButton::Send {Blind}{Escape} ; The * prefix allows it to fire whether or not Alt is held down.
#If
I've modified the example from the help page on this found here: https://www.autohotkey.com/docs/Hotkeys.htm#AltTabDetail
This was mainly to remap the Windows+Tab key to the Alt+Tab key in this example.
It opens the task view and waits for the user to click, escape or enter. The example from the help page has the alt key getting stuck for me so I changed it to work a little better.
Please let me know if this works for you all.
; Override the Left Win key and tab to Alt + Tab
; Help found here:
; https://www.autohotkey.com/docs/Hotkeys.htm#AltTabDetail
; #IfWinExist ahk_group AltTabWindow
#NoEnv
#SingleInstance force
SendMode Input
LWin & Tab::Send {Alt down}{tab} ; Asterisk is required in this case.
!LButton::
{
Click
Send {Alt up} ; Release the Alt key, which activates the selected window.
}
!Enter::
{
Send {Alt up} ; Release the Alt key, which activates the selected window.
}
~*Esc::
{
Send {Alt up} ; When the menu is cancelled, release the Alt key automatically.
;*Esc::Send {Esc}{Alt up} ; Without tilde (~), Escape would need to be sent.
}
I got ALT TAB to work with F1
By pressing F1 you can switch to the last window
While F1 is kept pressed you can move around with arrow keys or tab to select the window you need.
Code:
`F1::
Send, {ALT DOWN}{TAB}{TAB UP} ; If F1 is down it invokes the menu for switching windows.
KeyWait, F1 ; Show menu for switching windows by keeping ALT down until user physically releases F1.
Send, {ALT UP} ; If F1 is released release ALT key
return`
Documentation links
KeyWait
KeyList
I think this question was meant to be a simple request of: how to alt tab in Win10 using AHK, since win10 changed things up? -> I found the most simple solution as shown below... the code makes it necessary to keep the alt key down while the Win10 emu is open - then use the arrow keys an additional number of tabs (if you need three alt tabs, then it's "alt tab, then right 2", see?
macro key name::
{
Sleep 100
Send, ^c
Sleep 1000
Send, {alt down}{tab}
Sleep 400
Send, {right 2}{alt up}
Sleep 400
Send, ^v
Sleep 400
}
So just play with this snip in your code and you can jump passed the 'next' window(s) open.
Rossman

How can I keep modifier of hotkey active in AutoHotkey?

A media keyboard I'm using doesn't have a full set of keys, so I'm trying to map alternatives using AutoHotkey. Basically, I want to use the Alt Gr key together with some other keys to simulate the missing keys. This is what I've done:
<^>!,::send {Home}
<^>!.::send {End}
<^>![::send {PrintScreen}
<^>!]::send {Insert}
However, if I want to do the equivalent of Shift + Home (to select all text to the beginning of a line), this doesn't work as I'd hoped. I know I can put a * at the beginning of the line so that Home is still sent even when I'm holding Shift, but the problem is that I'd like the Shift key to still be active so that I get the equivalent of Shift + Home.
Likewise, if I want to do Alt + Print Screen then holding Alt while pressing Alt Gr + [ doesn't have the desired effect.
I assume I could set up extra rules to catch those combinations, but surely there must be a way to just have AutoHotkey not discard whatever modifier I'm holding at the time I hit the hotkey so that whatever combination I use it'll work?
EDIT (2014-07-16):
Here is the latest version of my script, which includes comments that make it clear what I'm wanting to achieve. Everything in this script works except for the last line. For some reason, even though I'm trying to send Alt + PrtScn it gets treated as just PrtScn.
; Home ( by pressing AltGr + , )
<^>!,::send {Home}
; Shift + Home ( by pressing Shift + AltGr + , )
+<^>!,::send +{Home}
; End ( by pressing AltGr + . )
<^>!.::send {End}
; Shift + End ( by pressing Shift + AltGr + . )
+<^>!.::send +{End}
; Insert ( by pressing AltGr + [ )
<^>![::send {Insert}
; Shift + Insert ( by pressing Shift + AltGr + [ )
+<^>![::send +{Insert}
; PrtScn ( by pressing AltGr + ] )
<^>!]::send {PrintScreen}
; Alt + PrtScn ( by pressing LeftAlt + AltGr + ] )
<!<^>!]::send !{PrintScreen}
Using the {Blind} attribute will pass on the modifier keys.
e.g.
<^>!,::send {Blind}{Home}
See: Send existing modifiers with a key in autohotkey?
It turns out that some of the combinations I wanted to do with Autohotkey, involving the AltGr key, are not possible due to AltGr itself actually being a combination of Control and Right Alt. Therefore, not all modifiers are available for use together with that key, and some of the AutoHotkey commands give unwanted/unexpected results when trying to use them together with AltGr.
The final version of the script I'm using with my new keyboard (the UK version of the Microsoft All-in-One Media Keyboard) is as follows:
; Set an initial state for the lock keys
SetCapsLockState, off
SetNumLockState, on
SetScrollLockState, off
; Home ( by pressing AltGr + , )
<^>!,::send {Home}
; Shift + Home ( by pressing Shift + AltGr + , )
+<^>!,::send +{Home}
; End ( by pressing AltGr + . )
<^>!.::send {End}
; Shift + End ( by pressing Shift + AltGr + . )
+<^>!.::send +{End}
; Insert ( by pressing AltGr + [ )
<^>![::send {Insert}
; Shift + Insert ( by pressing Shift + AltGr + [ )
+<^>![::send +{Insert}
; PrtScn ( by pressing AltGr + ] )
<^>!]::send {PrintScreen}
; Alt + PrtScn ( by pressing Alt + ] )
!]::send !{PrintScreen}
; Scroll Lock ( by pressing AltGr + \ )
<^>!\::send {ScrollLock}
; Pause/Break ( by pressing AltGr + p )
<^>!p::send {Pause}
; Win + Pause/Break ( by pressing Shift + Alt + p )
+!p::send #{Pause}
; Control + Pause/Break ( by pressing Shift + Ctrl + p )
+^p::send ^{CtrlBreak}
; Run Calculator ( by pressing AltGr + c )
<^>!c::Run Calc

How do you send an alt0189 to autohotkey

In word and other programs when you hold down the alt key and type 0189 on the number keyboard you will get the half inch symbol ½. How can I send this sequence in autohotkey using a hot key
Thanks in advance
Tim
In general: Send, {ASC 00189}
I do it this way:
; ================================== FRACTIONS ==================================
^2::
Send, ½
TrayTip, For 2 Squared,press Ctrl + Shift 2,1,1
Return
^3::
Send, ¾
TrayTip, For 3 Cubed,press Ctrl + Shift 3,1,1
Return
^4::Send, ¼
; ================================== POWERS ==================================
+^0::Send, °
+^1::Send, ¹
+^2::Send, ² ; Shift Control 2#
+^3::Send, ³ ; Shift Control 3#
Ctrl+2 = ½
Ctrl+3 = ¾
Ctrl+4 = ¼
ShiftCtrl + 0 = °
ShiftCtrl + 1 = ¹
ShiftCtrl + 2 = ²
ShiftCtrl + 3 = ³

Alt + Space + key in autohotkey

How can I create an Alt + Space + C shortcut in autohotkey? Alt + Space is !space but I don't see how I can add a third key without getting an error.
You can use the #If directive (requires AHK_L) in combination with the GetKeyState() function:
#If GetKeyState("Alt", "p")
Space & c::Traytip,, % a_thishotkey
#If
or you can use the Keywait command:
!space::
keywait, c, d, t0.6
If ErrorLevel
Traytip,, Alt and space
Else
Traytip,, Alt space and c
Return
This will also trigger an Alt+space outcome after 0.6 seconds if you don't press C.
If that is undesirable you can write it like this:
!space::
keywait, c, d, t0.6
If (!ErrorLevel) {
Traytip,, Alt space and c
Sleep, 2000
Traytip,, % a_thishotkey
} Return
!ErrorLevel means "not ErrorLevel"