Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you're on Windows, Auto HotKey is the ultimate tool for automating day to day little things that are hyper specific for your daily work flow. For everything else there's Bash / some scripting language.

You can end up with really big quality of life improvements from having a bunch of little things whipped up to solve your problems.



AutoHotkey is an ugly language to write in, but oh boy is it useful for gluing disparate Windows actions together.

Theoretically you can do the same thing that AHK does in a .net language or even Powershell but AHK is just easier to whip up something very quickly.

Still I wish there were better Python wrappers for Windows automation.


> Theoretically you can do the same thing that AHK does in a .net language or even Powershell but AHK is just easier to whip up something very quickly.

This is exactly how I see it too. 10+ years ago I would have written a C# app to do something that I can now do in AHK.

Of course there's limitations (I wouldn't write a super intensive native app in AHK) but for little workflow optimizations it's so good.

For example, I wanted a quick and dirty way to grab the hex color under my mouse cursor and copy it to my clipboard. With AHK it was:

    #h::
    MouseGetPos, MouseX, MouseY
    PixelGetColor, color, %MouseX%, %MouseY%
    StringLower, color, color
    clipboard := SubStr(color, 3)
And now when I press Windows + h as a global hotkey it does what I want. I set it up to start when Windows starts and it uses 1.5MB of memory. Can't really beat that for overall efficiency (few minutes of coding, doesn't take up much resources, etc.).

A while back I wrote a blog post on using AHK for defining global hotkeys. I still use that method today. If anyone cares, that's at: https://nickjanetakis.com/blog/remap-and-set-global-hotkeys-...


Your hex snippet produced my usual outcry when I read other's AHK scripts: "Wait, you can do THAT?!"

It's been added to my growing toolbox(which I lovingly call i3_emulator.exe), thanks!


The fun thing about it is I wouldn't classify myself as an AHK developer. I just picked apart a couple of scripts that I found on Google.

You can kind of understand what's going on with general programming experience and double checking their documentation.

In the hex code example it almost reads like pseudo code. Get the mouse position and store it into X / Y variables, grab the color under the mouse position, make it all lower case, copy it to the clipboard but trim out a few extra characters that was returned by a previous step.

How is your i3 emulator going? I tried that one tiling window manager AHK script (bug.n) but found it to be a little too buggy to use.


I have used both AHK and AutoIt and find AutoIt much simpler to understand (and also has clearer documentation).

https://www.autoitscript.com/site/autoit/


I thought it was still just a neat tool to automate clicks, but then I played Path of Exile for a bit and found POE Trade Macro. It stunned me what it could do. Hover over an item, hit a key, it performs an API call to lookup a price and display it in a popup window over the game.

At work we evaluated other solutions like Blue Prism for our internal apps but Auto Hot Key never got a mention. I wonder why.


Can Auto HotKey recognize images and click on them? For example, a specific button in an app or a web page?

This is one of the features that keeps me with Keyboards maestro, which keeps me from switching away from macOS.


I'm not an AHK wizard but to my understanding, the answer is "yes" to almost every "but can it do...?" questions.

In your case, from my limited understanding it would be no problem to identify a specific button in an app and then interact with it because you would be hooking into the app's low level window title / class / handles.

AHK comes with a "spy" tool where you can just move your mouse around and it gives you low level details about every window, and then you can write AHK scripts that interact with those things.

The script would look something like:

    ControlClick, OK, "My Cool App"
That would click the OK button in a window that has a title of "My Cool App". If you Google around for "auto hotkey, click button in app" you'll find a ton of examples.


I have limited experience with Keyboard Maestro but I do have some with AppleScript. It lets you do as you described, get windows, titles, UI elements. However this only works on native apps, you cant, for example, click a button on a webpage with a CSS selector or by scanning pixels of the window, ad far as I know. Can AHK do that? That would be super useful


While I've never done it, AHK seems to have an API for being able to interact with DOM elements.

Check the marked answer here: https://stackoverflow.com/questions/49516638/ahk-web-element...

The above answer shows both navigating to a new page that isn't open yet or interacting with an already loaded page based on the title of the tab.



Yes, Autohotkey can search for pixels and stuff:

https://www.autohotkey.com/docs/commands/PixelSearch.htm


Yes it is very easy to match image and click on it with AHK. For image matching use https://www.autohotkey.com/docs/commands/ImageSearch.htm for matching use bmp files! bmp files works mach better then png or jpg. For clicks there are several commands, just google them. Also take a look at https://www.autohotkey.com/docs/commands/CoordMode.htm


Is there any reason bmp would work better than png? I've always used png all this time.


I cannot tell why it is so but bmp image matching worked for me much faster then png on several PCs.


Yes! You can search for Bitmaps on the screen. Take a screenshot and crop to the button, save it as a .bmp, and then use the ImageSearch function (https://www.autohotkey.com/docs/commands/ImageSearch.htm).

It will return the (x,y) and you can then use the Mouse functions to interact with that location.






Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: