EmacsWiki: Auto Hot Key (original) (raw)
AutoHotkey is an open source scripting language for Windows that can automate and customize almost any action on your PC.
- Use virtually any key, button, or combination as a hotkey for your keyboard, mouse, joystick, and handheld remote controls.
- Expand abbreviations as you type them using hotstrings.
- Easily create your own graphical user interfaces and custom menus.
- Convert any script into an EXE file that will run on computers without AutoHotkey.
- Manipulate files, text, and windows belonging to almost any program.
- Call functions inside a DLL, such as standard Windows API functions.
- All of this and more in a simplified syntax that makes learning easy for beginners while offering powerful features for advanced users.
Emacs modes for editing AutoHotKey scripts
See AutoHotKey Mode for information on the Emacs major modes available for editing AutoHotKey scripts.
See also:
Discussion
Now that I see the page you wrote, I’m not sure we need it on the wiki – after all, if we have this page, why don’t we have pages for GIMP, GNU/Linux, Slackware, Debian, GNU screen, mail, sendmail, Tex, and a myriad of other pages? Slowly, the Emacs Wiki will look like an incomplete and unmaintained software directory.
I think such a page should relate to Emacs is some way. In this particular case, we already have the page AutoHotKey Mode that says everything there is to say (from the point of view of an Emacs user who doesn’t know what AutoHotKey is or does).
In short, I think we should replace all instances of AutoHotKey
with [http://www.autohotkey.com/wiki/ AutoHotKey]
and merge this page with AutoHotKey Mode (if necessary), and delete it. – AlexSchroeder
I agree with the above from Jonas, except what I would like to see if not here then somewhere, is a HowTo make use of AHK to generalize the emacs keystrokes to the entire windoze environment.
(Response to “make use of AHK to generalize the emacs keystrokes” by HCH: The examples given below could let someone write such a package. If I read this correctly, then one would want to map Control-P to Up and Control-F to Right. Then it would be a good idea to make it possible to send a Control-P or Control-F when one wants to get by the AHK script – possibly by just turning the script off. There are also tools in AHK, like the IfWinActive
lines below, to alter the behavior of the script based on the context. (Like not using it Task Manager.) ……… This all would make it possible to use Emacs keystrokes in Wordpad, Notepad, Word, all one’s spreadsheets and databases, and any web pages in Internet Explorer, for instance. There would be a problem with Control-X Control-F mapping to either Control-O or Control-N, depending on whether the file or folder already exists (but AHK is a powerful language). ) – TomBaker
So, on-topic for this page would be, e.g. information about how to use Autohotkey in conjunction with Emacs. I use the US keyboard layout, since I am a programmer, but I frequently need to type European diacritical characters when I write German or Swedish, or type my name. I have an Autohotkey setup with things like
:*?:ae/::ä
for all the diacriticals I use regularly. This doesn’t work in Emacs though. Autohotkey sends ä to the receiving application by sending simulated keystrokes for Alt-keypad-0 Alt-keypad-2 Alt-keypad-2 Alt-keypad-8, which in most Windows applications generates the character with decimal code 0228, ä. Emacs doesn’t support this, so I hacked together the equivalent functionality in Elisp:
(defvar jonas:alt-keypad-seq nil)
(defun jonas:alt-keypad-value (key) (case key (M-kp-0 0) (M-kp-1 1) (M-kp-2 2) (M-kp-3 3) (M-kp-4 4) (M-kp-5 5) (M-kp-6 6) (M-kp-7 7) (M-kp-8 8) (M-kp-9 9)))
(defun jonas:alt-keypad-translate (seq) (let ((acc 0)) (dolist (elem seq acc) (setq acc (+ (jonas:alt-keypad-value elem) (* 10 acc))))))
(defun jonas:alt-keypad () "" (interactive) (unless (eq last-command 'jonas:alt-keypad) (setq jonas:alt-keypad-seq nil)) (push last-command-char jonas:alt-keypad-seq) (if (= (length jonas:alt-keypad-seq) 4) (progn (ucs-insert (jonas:alt-keypad-translate (reverse jonas:alt-keypad-seq))) (setq jonas:alt-keypad-seq nil))))
(global-set-key [M-kp-0] 'jonas:alt-keypad) (global-set-key [M-kp-1] 'jonas:alt-keypad) (global-set-key [M-kp-2] 'jonas:alt-keypad) (global-set-key [M-kp-3] 'jonas:alt-keypad) (global-set-key [M-kp-4] 'jonas:alt-keypad) (global-set-key [M-kp-5] 'jonas:alt-keypad) (global-set-key [M-kp-6] 'jonas:alt-keypad) (global-set-key [M-kp-7] 'jonas:alt-keypad) (global-set-key [M-kp-8] 'jonas:alt-keypad) (global-set-key [M-kp-9] 'jonas:alt-keypad)
Another great thing about Autohotkey is that it allows you to remap the Caps Lock key, which is rather difficult in Windows. Just use
CapsLock::AppsKey
to make it a Super key—very useful in Emacs if you define your own keybindings. --JonasOster
Agreed. AutoHotKey does let the Emacs user at keys not otherwise available. ….. I always like a “Macro” key in the lower left corner of my keyboard, as typing “Control-X e” is a little cumbersome. I used to remap Control-Z for that, but that keystroke is pretty useful for other things and I defined F2 as a “Macro” key. But AutoHotKey lets me define Control-Capslock as “F2”.
#IfWinActive ahk_class Emacs
^Capslock::
send {f2}
return
#IfWinActive
Note the IfWinActive
lines. This is how to say “Only do this for Emacs”. For one thing, they keep stray F2 strokes from going to other windows. For another, I can use AutoHotKey
to define entirely different meanings to Control-Capslock for Excel, FireFox
, whatever… – TomBaker
Another great thing, that complements Emacs and all its use of modifiers, is the way that AutoHotKey
can handle them. Example – My laptop decided to have its HOME and END keys crowded onto the same keys as PgUp
and PgDn
; that is, HOME is actually Fn
+PgUp
, and END is actually Fn
+PgDn
. Well, that should have worked, technically, but I use Home and End all the time and need to reach them (1) without modifiers and (2) by feeling for them with my fingers. So I mapped them onto the F8 and F9 keys, so the gap between F8 and F9 can be found by feel. So I had this for a long time in my .emacs file….
(define-key global-map [ f8 ] [home])
(define-key global-map [ f9 ] [end] )
(define-key global-map [ S-f8 ] [S-home])
(define-key global-map [ S-f9 ] [S-end] )
(define-key global-map [ C-f8 ] [C-home])
(define-key global-map [ C-f9 ] [C-end] )
(define-key global-map [ S-C-f8 ] [S-C-home])
(define-key global-map [ S-C-f9 ] [S-C-end] )
(define-key global-map [ M-f8 ] [M-home])
(define-key global-map [ M-f9 ] [M-end] )
But AutoHotKey
will apply modifiers after the fact, so I took that out of .emacs and put this into my .ahk file…
f8::Home
f9::End
That is all that is needed to make chords like Control + Alt +F8 work. AutoHotKey
does the right thing in cases like that.
Actually, the Quick Time Player needed F8 and F9 as UP and DOWN, so I put this other stuff in front of that.
#IfWinActive ahk_class QuickTimePlayerMain
$f8::send {down}
$f9::send {up}
#IfWinActive
f8::Home
f9::End
(If I remember correctly, the dollar signs keep it from recursing in this case.) – TomBaker
One thing to add is that AutoHotKey and Autoit are derived from the same code base, so AutoHotKey tips here may work well with AutoIt
. – TomBaker