FrostCloud Forums  

Go Back   FrostCloud Forums > Blogs > The Emu's Roost

Greetings!

Philosophy, computers, plumage.
Rate this Entry

Fun with AutoHotkey

Posted 09-14-2008 at 03:27 PM by Dromiceius
Random bit of trivia: I don't use a mouse anymore. I have a mouse- it sits on one of the stacks of CDs on the shelf above my monitor. The batteries died in... March, I think, and I never bothered to replace them because I've replaced the mouse itself with an elaborate system of hotkeys.

I'm not exactly sure how this system evolved. It started when I began using AutoHotkey to set up some shortcuts. Each weekend I'd sit down and cook up an even bigger hack than the week before, and now I've accumulated some 1,000 lines of code, some of which is pretty neat.


First off, the obvious usage: tweaking a UI works by throwing input at it. Media Player Classic requires this if you don't have a mouse. It turns into an unusable brick of crap if you happen to call the playlist manager by pressing ctrl+7. You can't dismiss the playlist by pressing ctrl+7 a second time. You can't even navigate the listbox using the arrow keys. The only way to use or get rid of this window is to reach for the mouse, and compared to the time it takes to use hotkeys, mousing time adds up to a lot of wasted time very quickly. All it really takes is thirty lines in an AHK script fix all of that.

Firefox, too, is obviously not designed to be used without a pointing device, but trying to browse with only a keyboard presents only a few serious complications, one of them being Fx's complete inability to maintain focus on the current tab, especially if you happen to use ctrl+f or the type-to-find feature.

Ergo, I wrote subroutine that throws the cursor off to the side, bringing it into view only for the purposes of managing this stupid browser.

Code:
maintainfocus:
if WinActive("Mozilla Firefox") {
	Click 1014, 709, 0
	MouseGetPos,,,,mozclass
	ControlFocus,mozclass,Mozilla Firefox
	Gosub NumpadDot
}
return
Not a perfect solution, but not bad, either.


A solution that IS perfect: automating DownThemAll!

dTa is a skinned app, which is to say that it trades usability in order to look pretty. So, I wrote a dialog box to act as a frontend. That's right- GUI that is a frontend to another GUI. Heads might explode at that, but it works. I press Win+A in Firefox, type in the regexp for whatever group of files I want to download, and set a few options using shortcut keys. And that's it. My options are more robust than those provided implicitly by dTa. Therefore, I rule.


Another handy trick: pasting text into a console window:

Code:
^v::
	if not WinActive("ahk_class ConsoleWindowClass")
		SendPlay {RCtrl Down}{v}{RCtrl Up}
	else
		Send %clipboard%
return
Copy 'realy_Long_mispelled_Annoying_Var' from a source file, paste into a command line for grepping, or whatever. Rejoice.

Of course, there's no simple way to know when a commandline process finishes without watching the damn thing. If a build takes more than a few seconds to complete, for example, then you're going to want to do something else for the duration, but come back to it once it's done. So, it's simple enough to have a timed subroutine watch the window for you, and play a sound when it completes:

Code:
enter::
if WinActive("Mingw")
	Gosub checkmingwtitle
return

checkmingwtitle:
	WinGetTitle,mingwtitle,Mingw*
	mingwoldtitle := mingwtitle
	SetTimer, getmingwtitle, 1000
return

getmingwtitle:
	WinGetTitle,mingwtitle,Mingw*
	if(mingwtitle<>mingwoldtitle){
		dosound("ding.wav")
		Dotip(mingwtitle)
		SetTimer, getmingwtitle, OFF
	}
return

Something most people probably do when they're introduced to AHK is map their Capslock key to something more useful than toggling Capslock:
Code:
Capslock::WinMinimize,A
I suppose gamers would want to selectively hijack the winkeys when playing something in fullscreen, if they hadn't already found a solution to that. You can actually bot most games using the input functions to mimic the inputs provided by a player. People do this, but there are better tools for that kind of thing.


AHK has all kinds of commands that can be used in different ways to perform many tasks. It's trivial, for example, to create a porn button, which might look like this:

Code:
randomporn:
Loop, C:\myporn\*.*,,1
    random,rand,0,10
    if(rand==10) {
        run, "c:\program files\pornviewer.exe" %A_LoopFileFullPath%
        break
    }
return
Along with important tools like PORN BUTTON, you could do silly, frivolous things like automated nightly backups and system maintenance.


But in spite of all that can be done through a bit of hacking and a basic grasp of interface design, sometimes you just need a mouse for five seconds to deal with some crappy dialog that doesn't have shortcut keys, and which you'll only need to deal with once.

For these annoyances, it's possible to use the keypad to emulate a mouse. It's simple on the most basic level; the 8, 4, 6, and 2 keys can move the cursor up, left, down and right.

Where it gets interesting is in using functions and global variables to create not only acceleration by holding the directional keys down, but also friction depending on what the mouse is hovering over.


...Of course you could just plug a mouse in, but where's the fun in that?
Posted in Computers
Comments 6 Email Blog Entry
Total Comments 6

Comments

Old
you are a computer nerd.......you have no grasp of philosophy.....shame................
Posted 09-19-2008 at 08:15 PM by lloydyrja lloydyrja is offline
Old
Dromiceius's Avatar
I wish I had a grasp of philosophy so I could go around the internet anonymously picking fights with complete strangers.

Seriously though, if one-line flames with 27 periods and zero reasoning is the best "philosophy" you can produce, you're not going to last very long here.
Posted 09-20-2008 at 04:03 AM by Dromiceius Dromiceius is offline
Old
Kzirb's Avatar
Hmm, that's funny, I counted 28.
Posted 09-21-2008 at 11:14 PM by Kzirb Kzirb is offline
Old
Dromiceius's Avatar
I should have written an AHK script to count them for me.
Posted 09-22-2008 at 12:02 AM by Dromiceius Dromiceius is offline
Old
Andy's Avatar
And Drom's reality - and identity- disappears amongst a blizzard of code...
Posted 10-03-2008 at 07:42 PM by Andy Andy is offline
Old
Dromiceius's Avatar
...hooray?

I'm not sure what you're getting at. This is an informal technical primer about a technology I found useful, and which I think would be accessible and useful to non-programmers, who wouldn't normally hear about it, or what it can do. It's not a philosophical treatise, nor anything very particular to myself.

Were you expecting something else? Are you even trying to criticize me about something? That's how it looks, but I honestly don't know what the point of that would be, so I'm confused.
Posted 10-04-2008 at 01:08 AM by Dromiceius Dromiceius is offline
 
Recent Blog Entries by Dromiceius

All times are GMT +1. The time now is 03:49 AM.



Powered by: vBulletin
Copyright 2000-2008 Jelsoft Enterprises Limited
Hosted and Maintained by The IceStorm Network