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.
Related
I use chrome bookmarks a lot, and I also often have to send people screen snippets very often, however I don't want all my bookmarks on display (some are sorta private). I know I could add them to the Other Bookmarks folder, but would rather easy access. What I've been doing for a while is hitting the bookmark shortcut (CTRL+SHIFT+B), then the snipping tool (WIN+SHIFT+S), taking my screenshot and then putting the Bookmarks back (CTRL+SHIFT+B). Eventually I decided to bite the bullet and spend some time automating it, so that hitting CTRL+SHIFT+S would close the Bookmark Bar, and letting go of the mouse (after taking the clipping) would put it back. This is what I came up with:
~#+s:: Send, ^+B
KeyWait, LButton, D
Send, ^+B
return
Although the first half works (Bookmarks go away, snipping tools open) at no point does the bar return. I've tried many things including setting up a timer, and waiting for the space bar instead of the mouse button, which i'd only hit when ready. I have also tested, and manually pressing the keys immediately after letting go the mouse button did indeed re-open the Bookmarks.
Would anyone be able to explain why this is happening? I would really appreciate any help!
First problem is that you put the first command on the same line as the hotkey definition.
This will create a one liner hotkey and the rest of the code below wont run.
Second problem is that you're sending the input to show bookmarks again while the screenshotting window is active. You're going to want to wait until chrome is active again.
This works:
#IfWinActive, ahk_exe chrome.exe
~#+s::
SendInput, ^+b
Sleep, 2000
WinWaitActive, ahk_exe chrome.exe
SendInput, ^+b
return
#IfWinActive
A bit of sleep so the screenshot window has time to open, and also added in #IfWinActive, because I'd assume you only want that hotkey to be active while you're on chrome.
Also switched over to SendInput and made the b lower case. Having it as uppercase would send Shift+B (on most keyboard layouts).
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.
How can I use AutoHotKey to simulate pressing control quote, then the menu bar button, then the down arrow when I press control p?
As a beginner, I have just been fiddling around with it, but I did not manage to make it work.
>^p::
Send ^{'}
Send {AppsKey}
Send {Down}
Right now, to me at least, it seems as though the only line of the code that is executing is "Send ^{'}" without anything under it executing.
I am working with a Help file as a Word 2007 document. I need to update the screenshots as I go through, so I'm trying to get AHK to select the 'Change Picture' option from the right click drop down menu when I press my key combination. I've got the code, and it works perfectly... the first time I use it. After that, I only see the right click menu flash and disappear. I suspect that the script from Send {Down 4} on is not executing because I can just barely see the 'Cut' option highlighted, but the selected image is not cut from the document, indicating that the Send {Enter} is also not being executed.
I cannot find anyone else who seems to be having this problem. If I manually reload my script, it works fine again, but only the once. Then it's back to flashing the drop down and nothing else. Any help would be greatly appreciated. I'm trying to get this process down to as few clicks as possible, but it's getting to the point where I'm wasting more time trying to solve my macro problems than I would just doing it the slow awkward way.
My script as it is now:
^!z::
Send +{F10}
Send {Down 4}
Send {Enter}
return
For clarification's sake:
When I remove everything following Send +{F10} and then use my hotkey, I get the right click menu displayed and not flashed, but again, only the first time I use it. After that, the menu goes back to flashing on the screen once. To compare, actually pressing Shift and {F10} displays the right click menu, and it does not disappear on lift.
If I move all three Send commands into one line to get Send +{F10} {Down 4} {Enter} The script executes the 'Cut' option from the right click menu, then moves the cursor down 4 lines and then sends the {Enter} keystroke. This set of actions works after the first use of the script, unlike previous instances.
In my copy of Word, the control key causes a secondary 'Layout Options' menu to pop up if there is an image selected. While I'm not sure why it's working for you the first time but not subsequently, when I test this at my end it works if I change two things:
Use mouseclick, right instead of Send +{F10}
Change the shortcut modifier from shift-ctrl to Win, i.e. set it to #z
You can try sending the keyboard shortcut instead of down command
SetBatchLines, 1
SetKeyDelay , 100 ; in miliseconds, keep increasing until your pc can hadle it
!x:: ; your hotkey in my case alt + x which is similar to ctrl + x for cutting text
Send +{F10}
Send {t} ; use the cut keyboard shortcut, for word should be 't'. if for some weird reason isn't change it
Send {Enter}
return
I'm not sure if this is common or not but I cannot get my code to run in this type of window. It works in all of my other windows except for the one, ahk_class SWT_Window0, I want it to work in... go figure.
My code is:
RButton::
SendInput {Click 166,350}
return
Pretty simple just move the cursor and click. It works in google chrome wundow spy scite and various other windows but not with the correct window. Any help would be awesome thanks!
Jack,
Have you tried to use the scan codes directly in your application?
Here is an example. It clicks the mouse at the current location and then sends a {Tab}. You need to change this for your needs. You can move your mouse to the right location first with MouseMove,%XPos3%,%YPos3%
F8:: ; Press F8 to start macro
Send, {vk01} ; Click left mouse button
;Send, {scYYY} ;
Send, {vk09sc00F} ; Send the Vk and SC codes for the {Tab} key.
Return
Let me know if this works