Wow, the one time in history I may be able to contribute something useful to a code-related discussion. I set up this script so I could quickly and easily open a blank plaintext notepad.exe instance at any time, which is super useful as a writer. When I hit tilde it opens, when I hit tilde again, it closes, with a save dialog if anything was written. It's the only thing my AHK does!
I like the detail how the very same key (just mostly in combination with meta/windows key) is kinda idiomatic toggle for terminal, what most programmers "live in". I wonder if digital graphic artists happen to launch their scratchpads or paint programs in a similar manner.
Btw, for use-cases when you need to keep the "toggled" window opened and do not want to close, minimize or hide it or something and just need the fastest flip to, flip back to previous window "toggle", super useful but (for me) long time forgotten native Windows hotkey is *`Alt + Escape`* - it simply switches to previous focused window without even showing window overview (like Alt+Tab).
So AutoHotkey *v1* boilerplate for such switcher/launcher then could be something like:
Or if you do not want that window to clobber the taskbar, you can use `WinHide` instead of that Alt+Win `send, !{escape}` and add WinShow to WinActivate, but it does not work well with some kinds of windows. Also for window detection it may sometimes be more suitable to use `ahk_exe` or `ahk_class`.
I do include Minimize-if-already-active though. I like to be able to temporary flip an application into focus (e.g. Outlook) and then return to what I was previously working on.
Plus a tweak: When launching, programs may open in the background because Windows attempts to prevent applications stealing focus when you are working in another program. I overcome this by focusing the tray before launching.
It uses AHK's window groups.
I only regret having written this in AHK v1, which was a bit of a pain in the neck.
I intend rewrite them in AHK v2, which looks like a halfway step to ES6 with lambdas, closures and all. So many quirks gone! I tried it a bit and it felt more fun and productive.
As a simpler alternative (which I use for work), one can pin the 10 most used applications on the taskbar and do:
- Win+<N> to launch, toggle, or choose a window from the Nth application
- Ctrl+Win+<N> to launch, toggle or cycle through the windows from the Nth application
- Shift+Win+<N> to launch a new window
- Alt+Win+<N> to bring up the Jump List
Then you can use a simpler hotkey manager (like PowerToys' Keyboard Manager) to bind to the Ctrl+Win+<N> shortcuts.
> Plus a tweak: When launching, programs may open in the background because Windows attempts to prevent applications stealing focus when you are working in another program. I overcome this by focusing the tray before launching.
Aaah! That explains some things. That does happen to me sometimes and it's a bit annoying. I got used to pressing my hotkey again when I noticed the taskbar icon blinking green to bring up the new window, or just spamming WinActivate and hope for the best. Thanks!
Yes, Win+<number> is also a gem that almost seems to be deliberately hidden, (like Win+T, Win+B). One thing that helps is to see actual numbers in the taskbar, what, to my knowledge, is currently possible in Windows 10 (only) with third-party app: https://ramensoftware.com/7-taskbar-numberer . For startup
will show same number for grouped windows so cycling will work.
Btw most tabbed interfaces have the same bindings for focusing first, second ... last tab (Ctrl+<number> in most browsers, Ctrl+9 for the last tab, usually).
I like to apply same "tab principles" to taskbar, so last thing missing here is to be able to "Ctrl+PgUp/PgDown" through windows in Taskbar order just like in sane browsers (with Win in place of Ctrl).
I attempted to do it with AHK but failed miserably, but luckily another third-party app, (7+ Taskbar Tweaker, from the same author as Numberer) can do that through advanced settings. Config in gist: https://gist.github.com/myfonj/62b4e0d393f4a97df5e9904df5e77...
(Sadly, none of those will probably ever work outside Windows 10 (?))
Ah, sorry, my bad, it should have been "Escape" instead of ~"Windows key"~.
`Alt + Escape`, that is. Thanks for pointing it out. Corrected.
(You see, I almost never use this shortcut directly, b/c I only exploit it in those AHK scripts to do the "to previous" flip without doing any additional persistence or querying in the script, so I messed up when recalling it. In fact I thought it was `Win+Escape`, tried it, found out it was `Alt+Escape` instead, and then finally wrote `Alt+Win`. Bad braining today.)
This is only slightly faster than hitting the Windows key, typing "Notepad", and hitting Enter.
Would be cool if it opened a single "notes.txt" document instead. That way you could bring up your notes, append what you want, and save/close it with a single hotkey.
It's about minimising friction in our tasks and reducing any unnecessary obstacles. Even seemingly minor actions that only take a few seconds can build up over time and generate a sense of frustration, especially when they become frequent.
Personally, I have found that dealing with this kind of friction can erode my overall productivity, as I unconsciously shy away from these tedious tasks that involve manual repetition, no matter how small. That's why many of us choose to invest a little time in coming up with these small automations that free us from the clutches of monotonous and repetitive tasks, allowing us to focus on the core of our work.
Autohotkey is amazing, but I wish it used a saner language. I struggled to write a reliable golden ratio version of aero snap [1]. Dealing with different monitors, sizes, etc doesn't seem like it should be so hard, but I always get tripped up by the bizarre Loop syntax or silent failures from some simple mistake that suck the fun out and I give up.
I found ahk python module [2] but combining it with the keyboard module doesn't work as well as autohotkey as a hotkey listener.
You know, that's part of what's been holding me back from using it for much besides remapping CapsLock to Control. Maybe it's time to sit down and write a Lisp DSL that compiles to it.
Or make it call a cloud service running a real program in a kubernetes cluster, which gets the hotkey and returns a script to interpret. If AutoHotKey does not have network and eval functions, they must be added ASAP
That's why Autohotkey v2 exists, which is... AHK's own Python3 moment, since it was available for years. Well, ok, stable release was only like a year ago, but I don't see much adoption.
I believe I’m using v2, since I written most of my scripts last year by most recent documentation which mentioned “old ways” sometimes. But it didn’t make a big difference in that regard.
TFA uses V2. I also started using AHK just in time to use V2. Of course it will take time for all the V1 users to migrate, but for anyone starting now it makes little sense to use V1.
it's just a bit tedious to convert even with the help of a converter, especially when you're dealing with libraries which you didn't write, but still very much worth it (you could maybe also do a lot of the conversion piecemeal and just run both for some time)
Part of the problem IMO is that AHKv2 is magnitudes better if you're a programmer, because it makes the entire language consistent and sane. But if most users aren't programmers, so they don't have the same burning incentive to switch.
I have swapped Caps Lock and Escape on my Linux personal laptop and I have grown used to it. So when I dual booted Windows on my machine, I used Powertoys[1] to achieve the same.
At work, I have no option to install Powertoys or Uncap[2] for that matter. AutoHotKey is the only way, but I'm unable to get it to work. I used this StackOverflow[3] answer, but with this, both Caps Lock and Escape send both of the keys. So I'm stuck occasionally messing up my Teams messages :)
Did you try scancode map registry[1]? I use it to swap Ctrl/CapsLock and it works well even with RDP softwares and run-as-admin apps which PowerToys couldn't handle.
With home row modifiers, Shift/Ctrl/Win/Alt are put underneath fdsa (and jkl;). -- This reduces the need to use pinky fingers for these keys, & the fingers get to remain on home row more.
I once used it on a citrix app. Can't use some of its functions that "find" controls on a form, so I set it to resize the window to a consistent size everytime and then execute its clicks at the right x,y coordinates.
I learned that you could click buttons before they were even drawn on the screen.
The AHK documentation is really good, and is a windows help file (chm). It is really fast, has a good enough indexed search, and example code is usually present.
i learned my first "programming" by doing autohotkey.
you write code line by line and the software expects to parse it one by one.
imagine my surprise when trying python for the first time and indentation error. WTF does indentation has to do with code?
i still cannot get over the fact that some interpreters and compilers and shit look at whitepace and go "this should be 4 space and not just 1 or 0. boo. wont run".
i get it, there has to be some form of beatification and stuff but why the hell wont the program run without proper indentation?
i have a problem at work, something tedious and my mind can think entire AHK programs. all i have to do is type them out and run.
Python uses indentation for nested scope (I think that's the right term). While other languages might use curly braces or even keywords like do and end to enclose loops and functions, Python uses indentation. It ensures code is readable, but coding newbies have to learn about whitespace errors AND scoping together. It's one of the parts of the language I dislike the most.
It's like learning to drive the car whilst sticking to the rules of the road and staying under the speed limit. It's not supposed to be fun.
Besides, I don't know what backwards IDE you used. I've been doing python for 15 years and have never had to manually indent squat, ever.
It sounds more like you didn't actually try python but read about the whitespace indentation somewhere and decided to chime in. Either that or you tried it in notepad.
look up a random autohotkey code. you can write it sideways, it will work. you can write it with indentation, it will work. it will work if the whole code is in a single line.
on one hand, it has the least amount of startup for a new programmer because it can teach you to do cool things.
on the other hand, like me, the "habits" get wrong because i never learned to do pretty code.
It's like learning to write but not wanting to learn punctuation. You might end up with the Ulysses but more likely than not you'd end up with something that other people and yourself won't be able to understand well when you look at it on the next day.
That said, I'm in the camp of curly braces (or equivalent) plus an autoindenter. Either a code formatter or the editor itself.
Braces and random indentation is the worst that can happen.
Scoping is essential for general purpose programming, so it is usually fused into the syntax of any GP language in a form of {…} or begin/do…end. Python is one of the languages which try to remove this character and keyword noise based on observation that to see scoping people usually correctly indent their scopes, so python makes indent itself important.
I can recommend using Notepad2 if you want to use GP languages but don’t want to use an IDE (which is understandable as it brings a cognitive overload when you learn). Notepad2 is a drop-in replacement for Notepad, but may be installed as a separate app. It’s not particularly for programming, but has related features that Notepad should have had for ages.
It's weird how python defaults to spaces rather than tabs, as tabs would make indentation errors less prevalent and a lot more obvious to people learning the language.
It won't run the program because the code is not correct, the same way a C compiler will refuse to compile a missing semicolon. If different indentation changes the meaning of a program from wipe the disk if condition true to wiping regardless of condition, that's a pretty bad change, so the interpreter rightly refuses to run incorrect programs.
For such simple and repetitive tasks I would suggest giving TinyTasks a try (https://www.tinytask.net/). There's no coding, you just press record do what ever needs to be done, stop recording, select how many times to repeat and play!
Yes, AHK is "lower level" regarding input tracking, so in KM left vs right modifiers aren't properly supported (though there are hackarounds that can make it work)
Then the sripting language is easier for batch editing and various permutations with proper functions and variables (though again KM can be partially hacked around to make it easier)
BetterTouchTool has a different approach, it's not a programming language per se, but lets you write JavaScript or AppleScript code to achieve anything you can do with AutoHotkey, and more. If BTT were available for Windows, I'd never touch AHK again.
I remember comparing AutoIt and AutoHotKey to pick which one to learn. The community being really open and seemingly twice as large at the time was why I selected AHK. Shame about the language syntax though, I still fight with it. But it is very powerful.
The syntax was one of the main reasons I chose AutoIt. For some reason I cannot stand the AHK syntax. For me personally it is hard to bring structure to an AHK code.
Every time I consider trying to take up coding, I remember that I have tried to write the most basic AHK scripts possible and cannot even get going with the tutorials. I find it completely impenetrable.
For me AHK is harder than other programming languages I learned (python, JS...).
Took me a while to figure out a decent environment for it:
VScode with Autohotkey Plus Plus extension, which allows debugging.
+chatGPT is super useful for it.
so don't get discouraged. If you want to learn coding I'd recommend learning python on some online code editor which requires zero setup. lookup 'python online', there are many websites for it. also Google Colab is awesome
ahk is fairly forgiving though compared to other languages. i found it harder to get into python even after years of getting proficient at ahk, and python is supposed to be one of the easier languages to learn.
maybe you just need to search online more or refine you searches. when i was learning ahk first i would nearly end up searching nearly every little thing i needed to do, and there was always a forum post with the answer or part of the answer
ChatGPT is actually pretty good at writing AHK scripts except it always writes a mixture of v1 and v2 syntax. Even if the script it creates won’t run, there’s usually enough to get you 80% of the way there.
The most useful thing I’ve made:
Select text anywhere and press ctrl-shift-1. Select text somewhere else (even in another application) and press ctrl-shift-2. Press ctrl-shift-3 and my graphical diff tool opens to show me the differences.
I've written more then 5000loc long program that plays an MMO for me!
It can already do most of the content that's in the game, but there still a lot of improvement needed.
But the development was so fun, every night I would start the script and then when I woke wake up, I would see where it broke and could then try to fix it and test it again the next night (because a lot of in-game content rests daily).
When I started writing the program, I was looking around to see if there's a library for Rust that would give me the same or at least similar functionality, but sadly I didn't find anything.
Don't get me wrong AHK is amazing, I just wanted to use the coding of this program as a way to better learn Rust!
I even had the program write a CSV file so that I could track the effectiveness of farming.
It really is incredible how powerful and easy to use AutoHotKey is!
That doesnt change the fact its simple cheating, getting an unfair advantage against other players. Beside this, botting is not what AHK is really good for
I wouldn't go that far. A lot of games have drudgery built in which isn't exciting past the first few times you've played it and rare bouts of willingness to do it again.
I would position part of what made Diablo 2 (not remake) last so long was bots on the ladder and the shops that provided the bots; no one "new" was playing the game at that time and everyone had "fair cheats" for rushing through the first two game modes [0] [1], and everyone had been using the "fair cheats" for years since they had been discovered. But the fair cheats needed other players to pull off, and this wasn't always reliable.
When the D2 shop farmers started botting, they realized it would be great advertisements to do specific types of common runs for leveling with the bots; the bots would grab any item worth value, but typically they just would repeatedly run common leveling/item farming areas on a predictable and guided schedule, dropping quick announcements about the shop in chat periodically (maybe several times per run which is usually around 5-15 minutes, and it was just a quick stylized message in the game chat.) There were enough bots that it wasn't flooding the available games to join, but you could almost always find a bot game to join and just follow until you were leveled.
Most players did this to get through Normal mode and often nightmare, as everyone just wanted to get a character ready for late Nightmare/Hell which is when the game is "fun" (better drops, more difficult monsters to fight, it was the point at which the game gets interesting in general for most players)
Without the bots and players "cheating" through the first 2 game modes, I'm not as confident people would have keep playing as long as they did. It wasn't "unfair" in my opinion as everyone had always wanted this, and it had automated what everyone was already doing; I'm not sure I see the difference between using AHK like the GP did and having a setup like what D2 had
0 - For the unfamiliar, Diablo 2 had three modes: Normal, Nightmare, and Hell; same game each time, but item drops are better and monster levels are changed to be more difficult, with monsters getting better attributes that made them more difficult. I am going to make a generalized statement that for most players, the game really begins at Nightmare if it's not one of your first few times playing the game
1 - By "fair cheats" I mean the game was exploited to ensure fast leveling without a lot of effort and also ways of bypassing the "boring" parts of the game that the game allowed, but likely not intentionally. Blizzard definitely couldn't solve this in game without substantial reworks, which they probably didn't want to do
I dont know about which years you talk about but at least in the early 2000s it was probably most common to let yourself be lead through Normal/Nightmare by others (e.g. clan members), which was a very nice part of companionship that helped foster engagement (and thus play count). But maybe you and me were just in different bubbles...
Not sure you'll see this, but I played from release until they released D2:R (I want to play D2:R, just no time :) )
Early on that's how it was, but later on they figured out glitch rushes (grushes) to help you fly through a1-a3 and you'd usually just trade your forge on NM/Hell for it.
After awhile though, this got really scammy from my experience (too many players who needed to be rushed would just flake)
Around 2018 or so when I played again, there were a LOT of shop bots running around doing the runs, and even better you had ENCHANT games where some suped up sorc would cast a ridiculously leveled ENCHANT on you (and your merc!) and even get you waypoints. I think I even remember the bots could do the grush, but I'm not confident I remember right on this element.
Basically, yes, old team-ups were great, when the player base was significant enough that you could do this :) In the last years of D2/LOD original, it was a little less possible to go that route.
The game that I play is called Crystal Saga. And while technically it is cheating, you don't get any real advantage doing so because the game it's designed in such a way that you can but pretty much every item with real money and many systems used to upgrade yourself can only be used by spending more money.
As such even if you were to automate every part of the game that's you can do as a free to play player you couldn't get close to those that support the developers with their money.
The gap is so big that you can't even hurt those players where as they can pretty much kill you in one shot.
But I personally play the game because of the people and the community, so none of the automation or money spending really matters to me.
Crystal Saga, it's a flash MMORPG as such it used to be browser based, but now you need their launcher or a non-mainstream browser. I do have hopes that Ruffle will bring the game back into modern mainstream browsers, but it's not quite yet there.
> I've written more then 5000loc long program that plays an MMO for me!
Interesting, that's how I got into AHK and programming in general too. It started as a simple timed clicking script, then became dynamic enough to handle variable timings, then I sped it up by embedding compiled machine code from a C function into the script as hex, decoded into a buffer, and called it with DllCall so more computer resources could go to running the game rather than the script. I went into more detail about my story here: https://news.ycombinator.com/item?id=23160930
AHK is one of the apps which locks me into using Windows. I use it to add characters like äöüß and áóúñ to my keyboard, to control the light level in the room and apartment, add timestamps like `08:39 –`, `2023-08-22 08:39:46` or 2023-08-22 — Tuesday` with the press of one/two buttons, shut down/turn on the power to my monitors with a Tasmota enabled power outlet when toggling the pause key and some other stuff.
I only wish it had the capability to use a second keyboard as a button surface to trigger stuff while eating up those key presses, so I'm resorting to a small bluetooth keyboard connected to a raspberry pi zero in order to get more buttons.
I wanted to comment this (Tom Scott used it to map buttons across 15 keyboards to unique emojis on a single computer) but it looks like as of March 2023, Luamacros has been abandoned :(
> Let's officially state what has been a reality for the last several years. I don't use Hidmacros/Luamacros any more and have no interest in improving it or even fixing existing bugs. I invest my personal time in other things which are more interesting for me now. So please don't expect any support from my side. I'm also removing all donation buttons.
It’s interesting seeing people in this thread complaining that AHK keeps them tied to windows, I feel the same about Keyboard Maestro on my Macs.
I switched to a 90% Windows environment at my new job. Gave Windows + AHK a shot to potentially reduce headaches when IT issues would pop up.
I couldn’t do it. AHK’s syntax is ridiculous, and whenever I would try to download and trial scripts I had to infer if it was v1 or v2. I switched back to the Mac with KM and am much happier for it.
If it's worth the money you could look for a cheapish keyboard with support for QMK or any other custom firmware and map some buttons to either F13-F24 or hard to trigger combos like ctrl-alt-shift-P or the like.
i switched to linux a few years and it was really tough losing the 5 years of ahk scripts i had built up, but windows was annoying me that much that i had to switch.
you need multiple programs on linux to do something similar to ahk and nothing ive tried has come close to how simple ahk is or how you can make complex key mappings with it.
i have got into python though and have been able to do some fun stuff with that so there's that at least
In Windows, everything is part of the operating system. You just set the window flags, you just beep the audio, you just send WM_CLOSE, you just disable MouseKeys. In Linux, everything is a specific program, with a name, and with commonly used alternatives. Your program to move a window to a particular location must be compatible with the program for having windows at all (X or Wayland), the program for laying windows out (dwm? KWin?), and probably the program for the desktop (GNOME? KDE?). The net effect is one where a user is probably able to write their own AHK-style scripts, but sharing them around is basically impossible, and figuring out what to do is much harder due to navigating a forest of tool-specific documentation.
25-key MIDI controller? There are a few people who have gotten AHK to send/receive MIDI, and you can pick up a cheap B-stock controller for far less than a mechanical keyboard.
I have a Preonic keyboard running QMK[1] and have a dedicated MIDI layer so I can still use it as a regular keyboard if I want to. I then use dannywarren/AutoHotkey-Midi[2] to listen for hotkeys.
This has been way more reliable for me than listening for trying to use hotkeys like Ctrl-Alt-F13 or things like that, as they'll never conflict with something I might be in the process of typing. The only catch with that is if you want to use AHK to send keystrokes to a process running in elevated access, you'd need to start your AHK script as Administrator. That hasn't had an impact on me, though.
With AutoHotInterception AHK can differ between different keyboards/mice based on their hardware-id. You can have a separate keyboard with it's own layout, macros, etc.
- Insert date/timestamps shortcut (6 different formats, including ISO, and filename-friendly)
- PuTTY/SSH launcher shortcuts for often used hosts and serial ports
- Stateful DWIM Application Launcher for 10+ applications, e.g. Outlook (Win+O), Windows Terminal (Win+Space), Total Commander (Win+T), etc. (Either launches, activates, or minimizes depending on current state)
- Paste clipboard in plaintext (no format) in any aplication (Win+V)
- Paste clipboard removing newlines in any application (Win+Alt+V)
- AltGr input layer for special characters (æøåµΩ° and some emojis)
- Media & Volume shortcuts (start/stop/next, volume up, volume down)
Mind sharing these? My current job includes a lot of manual copying, at least until I can automate it. Especially the plaintext/no newlines paste sounds very useful!
We built Text Blaze [0] a Chrome Extension [1] that supports a lot of similar capabilities.
It lets you do text expansions on any website using hotkeys, include dynamic values like the date a week from today in your snippets, build form UI's [2], and include dynamic logic using formulas and if-statements [3] (it uses a dynamic reactivity model for formula's similar to spreadsheets).
One thing we are really excited about currently is using Text Blaze snippets to connect any website to an Airtable/Monday.com like spreadsheet using a lightweight SQL variant we created [3]. Combined with forms and formulas, this allows you to build mini-apps you can use on any site with a hotkey.
As others have rightly noted AHK is amazing for what it lets you do on Windows.
I've easily saved/earned over 100k USD from AHK.
However, the AHK language is not the most pleasant to use.
That leads to question why isn't there something as powerful available in Python
or say Lua.
Yes there is https://github.com/pywinauto/pywinauto but in practice it did not work as well as AHK.
It is just WinAPI underneath so C# would be another choice if there was a nice wrapper library.
I guess the answer on why AHK is so popular is that it is ugly but it works.
PyAutoGui is very good. I have been using it for a long time and rewrote some simple ahk automations with it recently. It's strictly not a one-to-one replacement (so I still use autohotkey) but the UI automation features are well-done.
The reason AHK is so popular is because the ugliness that most “real” programming languages won’t tolerate is what makes it so approachable in the beginning.
Upgrade to v2 if you haven't yet! It was just released earlier this year and makes the language a lot less ugly. No more command/function divisions, everything's just a function!
For my wedding I set up a "photobox" with AutoHotKey. I took a simple software to control my fiancees Nikon via USB and IrfanView on my Laptop.
I configured Irfanview to monitor a folder and always show the newest picture.
Wit AutoHotKey I made a simple GUI with 3 Buttons. Preview, Autofocus and "SNAP". Preview brought up the camera software in liveview mode. Autofocus triggered the Autofocus. "SNAP" brought up a large countdown, at 0 it triggered a photo. The it minimized the camera software and brought up IrfanView. After a few seconds it "reset" itself, so IrfanView got minimized and my button GUI got brought up again. My guests loved it and I saved hundreds of Euros for renting a photo box and I got great images out of it.
I didn‘t build a box itself. It was just the Nikon on a stand with a flash directed to the ceiling for better lighting.
My laptop on a small table infront of it to control it and work as a display.
I use ahk to send the clipboard as typed letters when dealing with certain vms or remote access or weird webpages and normal paste doesn't work. The shortcut is ctrl+b
Not sure if AutoHotKey is the tool for this, but, I am looking for a functionality such that, when I get a ping from MS Teams (say), I want some other system in my home network to notify me of it - perhaps a notification in my android phone?
It does, but it is extremely limited. The StreamDeck plugin covers essentially the entire (local) API surface. From what I glanced, it might even have been created for the Stream Deck plugin.
For everything else, you can either parse a log (have fun!) or ask your AD admin to create credentials so you can use graph API after an OIDC handshake (also have fun!)
I used to use an Ann Pro 2 keyboard. By default, h, j, k, l could be used as arrow keys when fn was held down. The fn keys also remapped '[]' to 'home' and 'end', ";'" to pgup, pgdown, and '/' to delete. It also had this feature where the caps lock key acted as a fn key when held down. I very quickly got used to holding the caps lock key with my left pinky to access all the keys I needed with my right hand. I became much more productive on this little 60% keyboard than on any full-sized one as I never had to move my fingers from the home row.
I've now switched to a qmk compatible Keychron V2 (65%) keyboard and remapped the keys exactly the same way. I'm very tempted to go back to a more compact 60% since I literally never use the arrow keys.
When I use my laptop on the go, AHK to the rescue. I found a script[0] that does almost the same thing, unfortunately, it fails when I use more than one modifier with the arrow keys. For example: shift + ctrl + left arrow to select one word to the left, which is shift + ctrl + caps lock + h in my case, doesn't work.
203 comments
[ 2.6 ms ] story [ 247 ms ] threadI haven’t yet played with AHK 2 and ChatGPT, but since she has a cutoff at 2021, she may not know be well versed in AHK 2.0
`::
IfWinActive Untitled - Notepad
WinClose
else
IfWinActive *Untitled - Notepad
WinClose
else
IfWinExist Untitled - Notepad
WinActivate
else
IfWinExist *Untitled - Notepad
WinActivate
else
Run Notepad
return
I think auto saving of unsaved documents is one of it's best features
That would defeat the point of having the notetaking window open instantly.
fyi, if you use the WinActive() or WinExist() functions you can combine different titles
If WinActive("Untitled - Notepad ahk_class Notepad") or WinActive("*Untitled - Notepad ahk_class Notepad")
maybe you don't have to put in the "ahk_class Notepad" bit, its been a while since i used ahk!
Btw, for use-cases when you need to keep the "toggled" window opened and do not want to close, minimize or hide it or something and just need the fastest flip to, flip back to previous window "toggle", super useful but (for me) long time forgotten native Windows hotkey is *`Alt + Escape`* - it simply switches to previous focused window without even showing window overview (like Alt+Tab).
So AutoHotkey *v1* boilerplate for such switcher/launcher then could be something like:
Or if you do not want that window to clobber the taskbar, you can use `WinHide` instead of that Alt+Win `send, !{escape}` and add WinShow to WinActivate, but it does not work well with some kinds of windows. Also for window detection it may sometimes be more suitable to use `ahk_exe` or `ahk_class`.I do include Minimize-if-already-active though. I like to be able to temporary flip an application into focus (e.g. Outlook) and then return to what I was previously working on.
Plus a tweak: When launching, programs may open in the background because Windows attempts to prevent applications stealing focus when you are working in another program. I overcome this by focusing the tray before launching.
and here's where I declare most of my hotkeys: https://github.com/diogotito/autohotkey-scripts/blob/desktop...
It uses AHK's window groups. I only regret having written this in AHK v1, which was a bit of a pain in the neck. I intend rewrite them in AHK v2, which looks like a halfway step to ES6 with lambdas, closures and all. So many quirks gone! I tried it a bit and it felt more fun and productive.
As a simpler alternative (which I use for work), one can pin the 10 most used applications on the taskbar and do:
- Win+<N> to launch, toggle, or choose a window from the Nth application
- Ctrl+Win+<N> to launch, toggle or cycle through the windows from the Nth application
- Shift+Win+<N> to launch a new window
- Alt+Win+<N> to bring up the Jump List
Then you can use a simpler hotkey manager (like PowerToys' Keyboard Manager) to bind to the Ctrl+Win+<N> shortcuts.
> Plus a tweak: When launching, programs may open in the background because Windows attempts to prevent applications stealing focus when you are working in another program. I overcome this by focusing the tray before launching.
Aaah! That explains some things. That does happen to me sometimes and it's a bit annoying. I got used to pressing my hotkey again when I noticed the taskbar icon blinking green to bring up the new window, or just spamming WinActivate and hope for the best. Thanks!
Btw most tabbed interfaces have the same bindings for focusing first, second ... last tab (Ctrl+<number> in most browsers, Ctrl+9 for the last tab, usually).
I like to apply same "tab principles" to taskbar, so last thing missing here is to be able to "Ctrl+PgUp/PgDown" through windows in Taskbar order just like in sane browsers (with Win in place of Ctrl).
I attempted to do it with AHK but failed miserably, but luckily another third-party app, (7+ Taskbar Tweaker, from the same author as Numberer) can do that through advanced settings. Config in gist: https://gist.github.com/myfonj/62b4e0d393f4a97df5e9904df5e77...
(Sadly, none of those will probably ever work outside Windows 10 (?))
Pressing alt + win key does nothing for me on this Windows 10 machine.
`Alt + Escape`, that is. Thanks for pointing it out. Corrected.
(You see, I almost never use this shortcut directly, b/c I only exploit it in those AHK scripts to do the "to previous" flip without doing any additional persistence or querying in the script, so I messed up when recalling it. In fact I thought it was `Win+Escape`, tried it, found out it was `Alt+Escape` instead, and then finally wrote `Alt+Win`. Bad braining today.)
Would be cool if it opened a single "notes.txt" document instead. That way you could bring up your notes, append what you want, and save/close it with a single hotkey.
https://www.joelonsoftware.com/2000/04/10/controlling-your-e...
; It is made in Autohotkey2.
I found ahk python module [2] but combining it with the keyboard module doesn't work as well as autohotkey as a hotkey listener.
[1]: https://github.com/idbrii/daveconfig/blob/main/win/autohotke... [2]: https://pypi.org/project/ahk/
:-)
(I am in the process of doing this inside OpenSCAD.)
Windows: https://github.com/randyrants/sharpkeys
Ubuntu Linux (don't know about other Linuxes): /usr/share/X11/xkb/symbols/pc
-> These solutions avoid needing to keep a keybinding application open. The Linux solution unfortunately resets after every version upgrade.1. Do your multiline hotkeys have `Return` in them, or are they in braces?
2. Do you write `Send Foo` or `Send "Foo"`?
If you're doing the former, then I really recommend upgrading to v2, it makes a huge difference.
Dreams of a universal hotkey listener you could use in any language via some wasm plugin magic?
At work, I have no option to install Powertoys or Uncap[2] for that matter. AutoHotKey is the only way, but I'm unable to get it to work. I used this StackOverflow[3] answer, but with this, both Caps Lock and Escape send both of the keys. So I'm stuck occasionally messing up my Teams messages :)
[1]: https://github.com/microsoft/PowerToys [2]: https://github.com/susam/uncap [3]: https://stackoverflow.com/questions/38558376/how-to-map-caps...
[1] https://superuser.com/questions/550679/where-can-i-find-wind...
[0] https://github.com/jtroo/kanata
I'd also suggest "home row modifier keys" (or "home row mods").
The idea is to have the key behave the same when tapped, but differently if held. (e.g. https://github.com/evilC/TapHoldManager implements this for AHK)
With home row modifiers, Shift/Ctrl/Win/Alt are put underneath fdsa (and jkl;). -- This reduces the need to use pinky fingers for these keys, & the fingers get to remain on home row more.
https://github.com/hwalinga/dotfiles/blob/master/CapsLockCtr...
It also implements the double feature functionality of CapsLock that now functions as Ctrl when pressed with another key, and just Esc when tapped.
I learned that you could click buttons before they were even drawn on the screen.
The AHK documentation is really good, and is a windows help file (chm). It is really fast, has a good enough indexed search, and example code is usually present.
you write code line by line and the software expects to parse it one by one.
imagine my surprise when trying python for the first time and indentation error. WTF does indentation has to do with code?
i still cannot get over the fact that some interpreters and compilers and shit look at whitepace and go "this should be 4 space and not just 1 or 0. boo. wont run".
i get it, there has to be some form of beatification and stuff but why the hell wont the program run without proper indentation?
i have a problem at work, something tedious and my mind can think entire AHK programs. all i have to do is type them out and run.
i want to do a loop, i dont want to learn to be forced to understand indentation. that kills the enthusiasm imo.
Besides, I don't know what backwards IDE you used. I've been doing python for 15 years and have never had to manually indent squat, ever.
It sounds more like you didn't actually try python but read about the whitespace indentation somewhere and decided to chime in. Either that or you tried it in notepad.
once the code gets more elaborate, syntax highlighting and the likes do indeed make ones life easier
on one hand, it has the least amount of startup for a new programmer because it can teach you to do cool things. on the other hand, like me, the "habits" get wrong because i never learned to do pretty code.
That said, I'm in the camp of curly braces (or equivalent) plus an autoindenter. Either a code formatter or the editor itself.
Braces and random indentation is the worst that can happen.
I can recommend using Notepad2 if you want to use GP languages but don’t want to use an IDE (which is understandable as it brings a cognitive overload when you learn). Notepad2 is a drop-in replacement for Notepad, but may be installed as a separate app. It’s not particularly for programming, but has related features that Notepad should have had for ages.
- KeyboardMaestro is pretty equal, but is paid and takes a more gui-centric approach to automation building. Definitely more user-friendly.
- BetterTouchTool has a lot of intersecting features, but is more catered to gui scripting and gestures.
- Alfred has introduced automation scripts and triggers.
- There is also Shortcuts, which is sometimes quite odd to use and limited, but has the advantage of Workflows working on mac and iOS/iPadOS.
Keyboard Maestro has a great interactive UI, and also built-in UI panels that are also great as "cheat sheets"
BetterTouchTool is superb in touchpad/mouse control (but can also do shortctuts)
The alien syntax, the incompatibilities between versions, the outdated information on the internet made it difficult to learn.
I'd recommend to just use python with a library like pyautogui and similar.
Took me a while to figure out a decent environment for it: VScode with Autohotkey Plus Plus extension, which allows debugging.
+chatGPT is super useful for it.
so don't get discouraged. If you want to learn coding I'd recommend learning python on some online code editor which requires zero setup. lookup 'python online', there are many websites for it. also Google Colab is awesome
maybe you just need to search online more or refine you searches. when i was learning ahk first i would nearly end up searching nearly every little thing i needed to do, and there was always a forum post with the answer or part of the answer
The most useful thing I’ve made: Select text anywhere and press ctrl-shift-1. Select text somewhere else (even in another application) and press ctrl-shift-2. Press ctrl-shift-3 and my graphical diff tool opens to show me the differences.
I've written more then 5000loc long program that plays an MMO for me!
It can already do most of the content that's in the game, but there still a lot of improvement needed.
But the development was so fun, every night I would start the script and then when I woke wake up, I would see where it broke and could then try to fix it and test it again the next night (because a lot of in-game content rests daily).
When I started writing the program, I was looking around to see if there's a library for Rust that would give me the same or at least similar functionality, but sadly I didn't find anything.
Don't get me wrong AHK is amazing, I just wanted to use the coding of this program as a way to better learn Rust!
I even had the program write a CSV file so that I could track the effectiveness of farming.
It really is incredible how powerful and easy to use AutoHotKey is!
If the game is boring enough that it can be played by an ahk script, then it probably isn't the most interesting game in the first place.
The ahk game sounds like more fun to me.
I would position part of what made Diablo 2 (not remake) last so long was bots on the ladder and the shops that provided the bots; no one "new" was playing the game at that time and everyone had "fair cheats" for rushing through the first two game modes [0] [1], and everyone had been using the "fair cheats" for years since they had been discovered. But the fair cheats needed other players to pull off, and this wasn't always reliable.
When the D2 shop farmers started botting, they realized it would be great advertisements to do specific types of common runs for leveling with the bots; the bots would grab any item worth value, but typically they just would repeatedly run common leveling/item farming areas on a predictable and guided schedule, dropping quick announcements about the shop in chat periodically (maybe several times per run which is usually around 5-15 minutes, and it was just a quick stylized message in the game chat.) There were enough bots that it wasn't flooding the available games to join, but you could almost always find a bot game to join and just follow until you were leveled.
Most players did this to get through Normal mode and often nightmare, as everyone just wanted to get a character ready for late Nightmare/Hell which is when the game is "fun" (better drops, more difficult monsters to fight, it was the point at which the game gets interesting in general for most players)
Without the bots and players "cheating" through the first 2 game modes, I'm not as confident people would have keep playing as long as they did. It wasn't "unfair" in my opinion as everyone had always wanted this, and it had automated what everyone was already doing; I'm not sure I see the difference between using AHK like the GP did and having a setup like what D2 had
0 - For the unfamiliar, Diablo 2 had three modes: Normal, Nightmare, and Hell; same game each time, but item drops are better and monster levels are changed to be more difficult, with monsters getting better attributes that made them more difficult. I am going to make a generalized statement that for most players, the game really begins at Nightmare if it's not one of your first few times playing the game
1 - By "fair cheats" I mean the game was exploited to ensure fast leveling without a lot of effort and also ways of bypassing the "boring" parts of the game that the game allowed, but likely not intentionally. Blizzard definitely couldn't solve this in game without substantial reworks, which they probably didn't want to do
Early on that's how it was, but later on they figured out glitch rushes (grushes) to help you fly through a1-a3 and you'd usually just trade your forge on NM/Hell for it.
After awhile though, this got really scammy from my experience (too many players who needed to be rushed would just flake)
Around 2018 or so when I played again, there were a LOT of shop bots running around doing the runs, and even better you had ENCHANT games where some suped up sorc would cast a ridiculously leveled ENCHANT on you (and your merc!) and even get you waypoints. I think I even remember the bots could do the grush, but I'm not confident I remember right on this element.
Basically, yes, old team-ups were great, when the player base was significant enough that you could do this :) In the last years of D2/LOD original, it was a little less possible to go that route.
The game should incentivize you to play and enjoy, not farm activity #399
There are also legitimate accessibility issues this can resolve, but would be considered cheating in many games.
that’s probably the definition of how most programmers got started. Get off your high horse
As such even if you were to automate every part of the game that's you can do as a free to play player you couldn't get close to those that support the developers with their money.
The gap is so big that you can't even hurt those players where as they can pretty much kill you in one shot.
But I personally play the game because of the people and the community, so none of the automation or money spending really matters to me.
Sadly a lot of games nowadays have (shitty) anti cheat systems that just ban you if you have the process running or have the program installed
Interesting, that's how I got into AHK and programming in general too. It started as a simple timed clicking script, then became dynamic enough to handle variable timings, then I sped it up by embedding compiled machine code from a C function into the script as hex, decoded into a buffer, and called it with DllCall so more computer resources could go to running the game rather than the script. I went into more detail about my story here: https://news.ycombinator.com/item?id=23160930
I only wish it had the capability to use a second keyboard as a button surface to trigger stuff while eating up those key presses, so I'm resorting to a small bluetooth keyboard connected to a raspberry pi zero in order to get more buttons.
Apparently there is also this: https://github.com/evilC/AutoHotInterception
> Let's officially state what has been a reality for the last several years. I don't use Hidmacros/Luamacros any more and have no interest in improving it or even fixing existing bugs. I invest my personal time in other things which are more interesting for me now. So please don't expect any support from my side. I'm also removing all donation buttons.
Hammerspoon[1] seems to be the best option for macOS.
[1] https://www.hammerspoon.org/
[1] - https://en.m.wikipedia.org/wiki/Keyboard_Maestro
I switched to a 90% Windows environment at my new job. Gave Windows + AHK a shot to potentially reduce headaches when IT issues would pop up.
I couldn’t do it. AHK’s syntax is ridiculous, and whenever I would try to download and trial scripts I had to infer if it was v1 or v2. I switched back to the Mac with KM and am much happier for it.
Is there anything like KM for Windows??
you need multiple programs on linux to do something similar to ahk and nothing ive tried has come close to how simple ahk is or how you can make complex key mappings with it.
i have got into python though and have been able to do some fun stuff with that so there's that at least
Why is that? Is there something about Linux that makes it difficult to do all the stuff AHK can do on Windows?
I have a Preonic keyboard running QMK[1] and have a dedicated MIDI layer so I can still use it as a regular keyboard if I want to. I then use dannywarren/AutoHotkey-Midi[2] to listen for hotkeys.
This has been way more reliable for me than listening for trying to use hotkeys like Ctrl-Alt-F13 or things like that, as they'll never conflict with something I might be in the process of typing. The only catch with that is if you want to use AHK to send keystrokes to a process running in elevated access, you'd need to start your AHK script as Administrator. That hasn't had an impact on me, though.
[1] https://docs.qmk.fm/#/feature_midi
[2] https://github.com/dannywarren/AutoHotkey-Midi
https://lintalist.github.io/
https://gist.github.com/raveren/bac5196d2063665d2154
Spotify responds to Send {Volume_Up}/{Volume_Down}.
Any particular reason using Cmder and not Windows Terminal?
It lets you do text expansions on any website using hotkeys, include dynamic values like the date a week from today in your snippets, build form UI's [2], and include dynamic logic using formulas and if-statements [3] (it uses a dynamic reactivity model for formula's similar to spreadsheets).
One thing we are really excited about currently is using Text Blaze snippets to connect any website to an Airtable/Monday.com like spreadsheet using a lightweight SQL variant we created [3]. Combined with forms and formulas, this allows you to build mini-apps you can use on any site with a hotkey.
[0] https://blaze.today
[1] We're currently beta testing Mac and Windows desktop versions.
[2] https://blaze.today/guides/forms/
[3] https://blaze.today/formulas/reference/
[4] https://blaze.today/datablaze/docs/bsql/
However, the AHK language is not the most pleasant to use.
That leads to question why isn't there something as powerful available in Python or say Lua. Yes there is https://github.com/pywinauto/pywinauto but in practice it did not work as well as AHK.
It is just WinAPI underneath so C# would be another choice if there was a nice wrapper library.
I guess the answer on why AHK is so popular is that it is ugly but it works.
Few years back, I made a video and published a free downloadable AHK template.
https://www.learnqtp.com/get-productive-with-automation-auto...
I configured Irfanview to monitor a folder and always show the newest picture.
Wit AutoHotKey I made a simple GUI with 3 Buttons. Preview, Autofocus and "SNAP". Preview brought up the camera software in liveview mode. Autofocus triggered the Autofocus. "SNAP" brought up a large countdown, at 0 it triggered a photo. The it minimized the camera software and brought up IrfanView. After a few seconds it "reset" itself, so IrfanView got minimized and my button GUI got brought up again. My guests loved it and I saved hundreds of Euros for renting a photo box and I got great images out of it.
It clicked on pixels of a certain character in game to thieve an NPC, and could detect full inventory, bank and go again.
^+b::SendRaw %clipboard%
Anyway we can achieve this?
https://support.microsoft.com/en-us/office/connect-to-third-...
For everything else, you can either parse a log (have fun!) or ask your AD admin to create credentials so you can use graph API after an OIDC handshake (also have fun!)
I've now switched to a qmk compatible Keychron V2 (65%) keyboard and remapped the keys exactly the same way. I'm very tempted to go back to a more compact 60% since I literally never use the arrow keys.
When I use my laptop on the go, AHK to the rescue. I found a script[0] that does almost the same thing, unfortunately, it fails when I use more than one modifier with the arrow keys. For example: shift + ctrl + left arrow to select one word to the left, which is shift + ctrl + caps lock + h in my case, doesn't work.
[0] https://github.com/AlexP11223/hjkl-keybindings/blob/master/w...