Auto-HotKey GUI Button to simulate a keyboard button - autohotkey

I have a button on a gui Titled "F4," Now when i click that button i want it to simulate the F4 Button on my keyboard.
Is it possible to do it?
This is the button:
Gui, Add, Button, x20 y260 w50 h20, F4

Your question seems to be how to switch back to the orginal application, so that the data will be sent there, not to AHK itself.
I pasted an example below just for you to look at. At around line 83 you will see that I first check which window is active and then, if required, switch back to the previous window using !{Esc} , before sending the actual data. This was just an exercise which I wrote long ago, to create multiple paste options. I am sure there are lost of things that can be improved, but it will give you some idea as to how you can solve this.
#SingleInstance Force
#installKeybdHook
#Persistent
; Written by Robert Ilbrink, The Netherlands
Menu, Tray, Icon , Shell32.dll, 247, 1
SetTitleMatchMode, 2
Global Nr := 1
Next=Copy
x:=A_ScreenWidth-250
y:=A_ScreenHeight/2
; ================================== GUI ==================================
ShowListBox:
Gui, +Resize
Gui, Add, ListBox, h270 w195 vMyListBox gMyListBox, 01 %Array_1%|02 %Array_2%|03 %Array_3%|04 %Array_4%|05 %Array_5%|06 %Array_6%|07 %Array_7%|08 %Array_8%|09 %Array_9%|10 %Array_10%|11 %Array_11%|12 %Array_12%|13 %Array_13%|14 %Array_14%|15 %Array_15%|16 %Array_16%|17 %Array_17%|18 %Array_18%|19 %Array_19%|20 %Array_20%
;Gui, Add, Button, x10 y275 w45 h20, Paste
Gui, Add, Button, x10 y275 w45 h20, Refresh
Gui, Add, Button, x60 y275 w45 h20, Help
Gui, Add, Button, x110 y275 w45 h20, Special
Gui, +AlwaysOnTop
WinGet, State, MinMax,
If (State = -1)
Return
Else
Gui, Show, x%x% y%y%,Clippy CapsLock = %Next%
Return
GuiSize:
GuiControl, Move, MyListBox, % "w" A_GuiWidth - 20
GuiControl, Move, MyListBox, % "h" A_GuiHeight - 30
GuiControl, Move, Refresh, % "y" A_GuiHeight - 25
GuiControl, Move, Help, % "y" A_GuiHeight - 25
GuiControl, Move, Special, % "y" A_GuiHeight - 25
return
; ================================== SHORTCUTS ==================================
;+^1::MySend(Array_1) ; [Shift]+[Ctrl]+1 pastes item 1
;+^2::MySend(Array_2) ; [Shift]+[Ctrl]+2 pastes item 2
;+^3::MySend(Array_3) ; [Shift]+[Ctrl]+3 pastes item 3
;+^4::MySend(Array_4) ; [Shift]+[Ctrl]+4 pastes item 4
;+^5::MySend(Array_5) ; [Shift]+[Ctrl]+5 pastes item 5
;+^6::MySend(Array_6) ; [Shift]+[Ctrl]+6 pastes item 6
;+^7::MySend(Array_7) ; [Shift]+[Ctrl]+7 pastes item 7
;+^8::MySend(Array_8) ; [Shift]+[Ctrl]+8 pastes item 8
;+^9::MySend(Array_9) ; [Shift]+[Ctrl]+9 pastes item 9
;+^0::MySend(Array_10) ; [Shift]+[Ctrl]+0 pastes item 10
;+^q::MySend(Array_11) ; [Shift]+[Ctrl]+q pastes item 11
;+^w::MySend(Array_12) ; [Shift]+[Ctrl]+w pastes item 12
;+^e::MySend(Array_13) ; [Shift]+[Ctrl]+e pastes item 13
;+^r::MySend(Array_14) ; [Shift]+[Ctrl]+r pastes item 14
;+^t::MySend(Array_15) ; [Shift]+[Ctrl]+t pastes item 15
;+^y::MySend(Array_16) ; [Shift]+[Ctrl]+y pastes item 16
;+^u::MySend(Array_17) ; [Shift]+[Ctrl]+u pastes item 17
;+^i::MySend(Array_18) ; [Shift]+[Ctrl]+i pastes item 18
;+^o::MySend(Array_19) ; [Shift]+[Ctrl]+o pastes item 19
;+^p::MySend(Array_20) ; [Shift]+[Ctrl]+p pastes item 20
; ================================== NUMPAD SHORTCUTS ==================================
#Numpad1::MySend(Array_1) ; [Win]+1 pastes item 1
#Numpad2::MySend(Array_2) ; [Win]+2 pastes item 2
#Numpad3::MySend(Array_3) ; [Win]+3 pastes item 13
#Numpad4::MySend(Array_4) ; [Win]+4 pastes item 4
#Numpad5::MySend(Array_5) ; [Win]+5 pastes item 5
#Numpad6::MySend(Array_6) ; [Win]+6 pastes item 6
#Numpad7::MySend(Array_7) ; [Win]+7 pastes item 7
#Numpad8::MySend(Array_8) ; [Win]+8 pastes item 8
#Numpad9::MySend(Array_9) ; [Win]+9 pastes item 9
#Numpad0::MySend(Array_10) ; [Win]+0 pastes item 10
+#Numpad1::MySend(Array_11) ; [Shift]+[Win]+1 pastes item 11
+#Numpad2::MySend(Array_12) ; [Shift]+[Win]+2 pastes item 12
+#Numpad3::MySend(Array_13) ; [Shift]+[Win]+3 pastes item 13
+#Numpad4::MySend(Array_14) ; [Shift]+[Win]+4 pastes item 14
+#Numpad5::MySend(Array_15) ; [Shift]+[Win]+5 pastes item 15
+#Numpad6::MySend(Array_16) ; [Shift]+[Win]+6 pastes item 16
+#Numpad7::MySend(Array_17) ; [Shift]+[Win]+7 pastes item 17
+#Numpad8::MySend(Array_18) ; [Shift]+[Win]+8 pastes item 18
+#Numpad9::MySend(Array_19) ; [Shift]+[Win]+9 pastes item 19
+#Numpad0::MySend(Array_20) ; [Shift]+[Win]+0 pastes item 20
; ================================== SEND FUNCTION ==================================
MySend(Item)
{
ClipBoard = %Item%
IfWinActive, MultiClipBoard
Send, !{Esc}
Sleep, 100
Send, ^v{Space}
}
; ================================== SINGLE or DOUBLE CLICK ==================================
MyListBox: ; Single Click (Normal) or Double Click (DoubleClick) to paste data back to other application
if A_GuiControlEvent <> Normal ; Alternatively use "DoubleClick"
return
GuiControlGet, MyListBox ; Retrieve the ListBox's current MultiClipBoard.
StringTrimLeft, ClipBoard, MyListBox, 3
Send, !{Esc}
Sleep, 200
Send, ^v
;Send, {Enter}
;SendInput, %MyListBox%{Tab}
return
; ================================== PASTE BUTTON ==================================
ButtonPaste: ; Select an item with [Up] / [Down] arrows and press [Paste] to paste data back to other application
Gui, Submit, NoHide
StringTrimLeft, ClipBoard, MyListBox, 3
Send, !{Esc}
Sleep, 200
Send, ^v
;SendInput, %MyListBox%{Tab}
Return
; ================================== EXIT / CLOSE BUTTONS ==================================
GuiClose:
GuiEscape:
Gui, Destroy
ExitApp
; ================================== REFRESH BUTTON ==================================
ButtonRefresh:
Gui,+LastFound
WinGetPos,x,y,w,h
Gui, Destroy
GoSub, ShowListBox
Return
; ================================== Copy Into the List ==================================
Browser_Favorites:: ; [Star] key to copy to clipboard.
!c:: ; [Alt]+c to copy to multiClipboard.
#c:: ; [Win]+c to copy to multiClipboard.
Send, ^c
Sleep, 100
Array_%Nr% := ClipBoard
Nr++
If (Nr >20) ; wrap around after 20 entries
Nr:=1
WinGet, State, MinMax, MultiClipBoard
If (State = -1)
Return ; GUI, Show
Gui,+LastFound
WinGetPos,x,y,w,h
Gui, Destroy
GoSub, ShowListBox
Return
; ================================== CLEAR / OPEN / SAVE ==================================
ButtonSpecial:
SetTimer, ChangeButtonNames, 30
MsgBox, 4098, Special Action, [Clear]`, Clears all items`n[Open]`, Open a list`n[Save]`, Save current list.
IfMsgBox, Abort ; ================================== CLEAR ==================================
{
MsgBox, 4100,, Are you sure to clear the list?
IfMsgBox No
Return
Nr := 1
Loop, 20
{
Array_%Nr% =
Nr++
}
Nr := 1
Gui,+LastFound
WinGetPos,x,y,w,h
Gui, Destroy
GoSub, ShowListBox
Exit
}
Else ifMsgBox, Retry ; ================================== OPEN ==================================
{
FileSelectFile, SelectedFile, 3, , Open a file, Text Documents (*.txt)
If SelectedFile =
Exit
Else
{
Loop, read, %SelectedFile%
{
If A_LoopReadLine =
Break
Array_%A_Index% := A_LoopReadLine
If (A_Index > 20)
Break
Nr := A_Index + 1
}
}
Gui,+LastFound
WinGetPos,x,y,w,h
Gui, Destroy
GoSub, ShowListBox
Exit
}
Else ifMsgBox, Ignore ; ================================== SAVE ==================================
{
FileSelectFile, SelectedFile, S, , Save the list as a Text Document, (*.txt)
StringReplace, SelectedFile, SelectedFile, `.txt,
FileDelete, %SelectedFile%.txt
Loop, 20
{
CurrentLine := Array_%A_Index%
FileAppend, %CurrentLine%`n, %SelectedFile%.txt ; % Array_%A_Index%, doesn't work
}
}
Exit
; ================================== HELP BUTTON ==================================
ButtonHelp:
MsgBox, , MultiClipBoard Help, Press [Alt]+c or [Win]+c to copy highlighted data onto the clipboard (TEXT only).`n`nClick on an item to paste it to the last active application.`n`nPress [Refresh] to refresh the screen after items were added while minimized.`n`nPress [Special] to select`n[Clear] to clear the list (after confirmation),`n[Load] to load items from a file or`n[Save] to save current items to a file. `n`n[Shift]+[Ctrl]+[nr] (1...0) will paste item 1...10.`n[Shift]+[Ctrl]+[letter] (qwertyuiop) will paste item 11...20.
; ================================== RENAME STANDARD MSGBOX BUTTONS FOR SPECIAL MENU ==================================
ChangeButtonNames:
IfWinNotExist, Special Action
return ; Keep trying.
SetTimer, ChangeButtonNames, off
WinActivate
ControlSetText, Button1, &Clear
ControlSetText, Button2, &Open
ControlSetText, Button3, &Save
return
; ================================== ToggleCopy ==================================
CapsLock::
Send % "{CTRL DOWN}" (!paste ? "c" : "v") "{CTRL UP}"
;SoundBeep, % (!paste ? "300" : "3000"), 100
paste := !paste
;SplashTextOn, 150, 20,%WindowTitle%, % (!paste ? "Press " MyKey " to Copy" : "Press " MyKey " to Paste")
;WinMove, %WindowTitle%, , 800, 5
Menu, Tray, Icon , Shell32.dll, % (paste ? "248" : "247"), 1 ; Toggle between Up/Down Arrow in Icon
Next:=(!paste ? " Copy" : " Paste")
Gui,+LastFound
WinGetPos,x,y,w,h
Gui, Destroy
GoSub, ShowListBox
Send, !{Esc}
Return
; ================================== END ==================================

Taken from this forum post:
Gui, +LastFound +AlwaysOnTop -Caption +E0x08000000
Gui, Font, s22, Arial
Gui, Add, Button, x0 y0 w100 h50 gButton, F4
Gui, Show, x0 y0 w100 h50 NoActivate
; Define a hotkey to show/hide the Gui:
F1::
toggle := !toggle
If (toggle)
Gui, Cancel
else
Gui, Show, NoActivate
return
Button:
SendInput, {F4}
return

Related

Surrounding Clipboard with quotes in URL

Warning: I'm very new to this.
I'd like to make Google searches quicker by assigning a hotkey to search a text selection (in web browser) and surrounding that search with quotes (to get exact matches).
I've tried using bits of code I have found, but so far I can only search the selected text on Google, but don't know how to surround the selected text in quotes in the search.
^!d:: ;
prevClipboard := ClipboardAll
SendInput, ^c
ClipWait, 1
if !(ErrorLevel) {
Clipboard := RegExReplace(RegExReplace(Clipboard, "\r?\n"," "), "(^\s+|\s+$)")
If SubStr(ClipBoard,1,7)="http://"
Run, % Clipboard
else
Run, % "https://www.google.com/search?q=" Clipboard
}
Clipboard := prevClipboard
return
This simply opens a google search with the clipboard.
I cannot find out how to make it so "Clipboard" is searched instead of Clipboard.
Any suggestions? Thanks!
Run is a command and variables in commands have to be enclosed in percent signs.
To include an quote, specify two consecutive quotes twice:
Run, http://www.google.com/search?q=""%Clipboard%""
If you want to do a "Phase google search" from any Selected Text (And From Out Everywhere, on your Computer System.)
Then you can try this AHK Script.
you can [Select any Text] and then you can click the [F1] key from your Keyboard Device.
The Computer Find automatic out where it can do the Query Search (us 100x results) and what Browser it must use.
Example1.ahk
;#notrayicon
#SingleInstance force
GroupAdd, Browser, ahk_class Chrome_WidgetWin_1 ; Chrome or Iron
GroupAdd, Browser, ahk_class IEFrame ; Internet Explorer
GroupAdd, Browser, ahk_class MozillaWindowClass ; FireFox
GroupAdd, Browser, ahk_class ApplicationFrameWindow ; Edge
; here you can change the variable into exact search [
quote1 = "
; here you can change the variable into exact search ]
quote2 = "
; here you can change the variables intitle: - inurl: - inanchor: - allinurl: - allinanchor:
insearch = allintitle:
; + = Shift
; ! = Alt
; ^ = Ctrl
; # = Win (Windows logo key)
esc::exitapp ;You can click the (esc) key to stop the script.
f1::
If WinActive("ahk_group Browser")
{
sendinput ^c ;copy the selected text to clipboard memory
sleep 150
sendinput ^t ;CTRL+t make a new tab + goto address bar - use CTRL+L for the active tab + goto address bar
sleep 150
texta = https://www.google.com/?gfe_rd=cr&gws_rd=cr#q=%insearch%%quote1%
textb = %clipboard%%quote2% ;selected text
textc = &lr=lang_us&hl=us&num=100 ; google parameters
clipboard=%texta%%textb%%textc%
sleep 150
sendinput ^v ; paste the selected text
sleep 250
send {enter}
clipboard=%textb%
} else {
sendinput ^c ;copy the selected text to clipboard memory
sleep 150
texta = https://www.google.com/?gfe_rd=cr&gws_rd=cr#q=%insearch%%quote1%%quote1%
textb = %clipboard%%quote2%%quote2%%quote2% ;selected text
textc = &lr=lang_us&hl=us&num=100 ; google parameters
clipboard=%texta%%textb%%textc%
run %clipboard%
clipboard=%textb%
}
return

Hold RMB after button and click

I can't figure this out.
I'm trying to accomplish something like this:
Press a GUI button
When I click the mouse next hold the RMB
When I click again release the RMB
Current work:
Toggle=0
GUI, Add, Button, w50 h50, Nbutton
GUI, Show, x50 y50
return
ButtonNButton:
{
Toggle:=!Toggle
}
if GetKeyState("LButton","P")
if (Toggle == 1)
MsgBox, Do
Toggle:=!Toggle
return
This should work to accomplish what you want.
Note that right now, this example script is limited to only work in Notepad. You should update the script to target whatever program/game/window you want the hotkey to be active in.
Toggle := 0
GUI, Add, Button, w50 h50, Nbutton
GUI, Show, x50 y50
return
ButtonNButton:
Toggle:=!Toggle
; Update this line to match whatever window you want the hotkey active
; in, or delete this line to make the hotkey active everywhere.
Hotkey, IfWinActive, ahk_class Notepad
if Toggle
{
Hotkey, ~*LButton Up, RBSwitch, On
}
else
{
if GetKeyState("RButton") ;release RButton when hotkey is disabled
Send {RButton Up}
Hotkey, ~*LButton Up, RBSwitch, Off
}
RETURN
RBSwitch:
if GetKeyState("RButton")
Send {RButton Up}
else
Send {RButton Down}
RETURN

autohotkey - Trying to delete random items in Listbox

I'm trying a parsing loop, this works good except I can't delete the first item in the list. Probably something to do with the backtick n. Can't figure it out yet!
Update - OK, needed to duplicate the StringReplace line without a backtick n, so as to get the first item in the list.
Gui, Add, ListBox, 8 x26 y37 w100 h100 vColorChoice, Red|Green|Blue|Black|White
Gui +Delimiter`n
Gui, Add, Button, Default, Delete
Gui, show
return
ButtonDelete:
Gui, Submit, NoHide
ControlGet, ListBoxContents, List,, ListBox1
StringReplace, ListBoxContents, ListBoxContents, |, `n, All
msgbox %ColorChoice% ; ColorChoice here contains the files selected to delete
Loop, Parse, ColorChoice, `n
{
StringReplace, ListBoxContents, ListBoxContents, %A_LoopField%`n
StringReplace, ListBoxContents, ListBoxContents, %A_LoopField%
msgbox %ListBoxContents%
}
GuiControl,, ColorChoice, `n%ListBoxContents%
return
GuiClose:
ExitApp

AHK: closing a window whenever it pops up

I wrote an AHK script designed to copy a text from Adobe Acrobat when I press F9. It then changes it according to a regex and shows the copied text in tooltip. Additionally, I added code to automatically close an annoying window that Acrobat sometimes shows when coping a text, an infamous There was an error while copying to Clipboard. An internal error occurred. When this window doesn't show up, the script keeps showing a tooltip, which is designed to close after a specified amount of time. I've been banging my head against the wall but I don't know how to correct this.
;#NoTrayIcon
#Persistent
#SingleInstance
F9::
#If WinActive("ahk_exe Acrobat.exe")
{
Clipboard:=""
send,^c
ClipWait, 1
Clipboard := RegExReplace(Clipboard, "\r\n", " ")
SetTimer,CheckForMsgBox,100
CheckForMsgBox:
IfWinExist, Adobe Acrobat
{
Send {Enter}
SetTimer,CheckForMsgBox,Off
}
;Return
If (StrLen(Clipboard) < 120)
ToolTip % Clipboard
Else
ToolTip Copied
SetTimer, ToolTipOff, -1000
return
}
#If
ToolTipOff:
ToolTip
return
;#NoTrayIcon
; #Persistent ; (1)
#SingleInstance
SetTimer,CheckForMsgBox,100 ; (2)
return
#If WinActive("ahk_exe Acrobat.exe") ; (3)
F9::
clipboard:=""
send,^c
ClipWait, 1
Clipboard := RegExReplace(Clipboard, "\r\n", " ")
If (StrLen(Clipboard) < 120)
ToolTip %Clipboard%
Else
ToolTip Copied
SetTimer, ToolTipOff, -1000
return
#If ; turn off context sensitivity
ToolTipOff:
ToolTip
return
CheckForMsgBox:
; ControlSend, Control, Keys, WinTitle, WinText, ExcludeTitle, ExcludeText
ControlSend, , {Enter}, Adobe Acrobat ; Close this unwanted window whenever it appears
return
(1) Scripts containing hotkeys, hotstrings, or any use of OnMessage() or Gui are automatically persistent.
(2) SetTimer causes a subroutine (Label) to be launched automatically and repeatedly at a specified time interval.
https://autohotkey.com/docs/commands/SetTimer.htm
(3) Like the #IfWin directives, #If is positional: it affects all hotkeys and hotstrings physically beneath it in the script.
https://autohotkey.com/docs/commands/_If.htm

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