5
votes

I asked a question about an Autohotkey script I am using for emacs (in Cygwin) to remap the Ctrl and Alt keys. Here is the question: https://stackoverflow.com/q/15899963/1243435.

One way I have been testing my script is to open up emacs and use the C-h k feature which shows documentation for a key sequence. It allows me to confirm whether Autohotkey is doing what I expect.

However it seems that there are some complications, for instance it may be that the Cygwin terminal does not allow the sequence C-M-SPC to 'get through' to emacs, so emacs actually only receives C-SPC instead.

My question is thus: does Autohotkey have its own test facility which shows you what Autohotkey is receiving and sending when you press a few key combinations on your keyboard? If yes I would be able to confirm that my script is working fine or not, and then decide whether it is some other issue that is causing me problems in getting key sequences through to emacs.

Update based on answer suggested by Armin

On the suggestion from Armin, below is what I see in the AHK view screen after doing the following:

  1. mouse-click in the Cygwin window to activate it (I already have emacs running in there),
  2. press LeftAlt+h then k which I know AHK will convert into C-h k, this being the 'tell me what the next keyboard sequence means' in emacs,
  3. at the emacs help prompt press Left Win+Left Alt+SPACE,
  4. see that emacs shows me the documentation for C-M-@ (which is also bound to the key sequence C-M-SPC by the way),
  5. mouse-click back in the AHK view window and refresh with F5.

Here is the relevant section of the output in the AHK window (modulo a bit of shortening of the longer lines to stop word-wrapping here):

VK  SC  Type    Up/Dn   Elapsed Key     Window
----------------------------------------------------------
A4  038 h   d   4.18    LAlt            /cygdrive/c/...
A4  038 i   u   0.00    LAlt            
A2  01D i   d   0.00    LControl        
48  023     d   0.09    H               
48  023     u   0.09    H               
A4  038 h   u   0.05    LAlt            
A2  01D i   u   0.00    LControl        
4B  025     d   1.22    K               
4B  025     u   0.06    K               
A4  038 h   d   1.12    LAlt            
A4  038 i   u   0.00    LAlt            
A2  01D i   d   0.00    LControl        
5B  15B h   d   0.02    LWin            
A4  038 i   d   0.00    LAlt            
20  039     d   0.19    Space           
20  039     u   0.06    Space           
5B  15B h   u   0.16    LWin            
A4  038 i   u   0.00    LAlt            
A4  038 h   u   0.00    LAlt            
A2  01D i   u   0.01    LControl        
74  03F     d   1.90    F5                  C:\...\AutoHotkey.ahk ...

It shows a lot of things going on.

My understanding is that this proves that AHK is correctly converting my Left Alt+Left Win+SPACE to C-M-SPC.

Below is an explanation of why I think the proof is done.

Here is me pressing LAlt down, and it being converted into a down of LCtrl:

A4  038 h   d   4.18    LAlt            /cygdrive/c/...
A4  038 i   u   0.00    LAlt            
A2  01D i   d   0.00    LControl        

(but I am not sure what that u of LAlt is in the middle -- AHK explains that 'i=Ignored because it was generated by an AHK script').

Next is me pressing and releasing h:

48  023     d   0.09    H               
48  023     u   0.09    H               

so at this point emacs has received C-h.

Next I release LAlt, then press and release k.

A4  038 h   u   0.05    LAlt            
A2  01D i   u   0.00    LControl        
4B  025     d   1.22    K               
4B  025     u   0.06    K               

Emacs now goes into the help prompt for 'describe key sequence'.

Then I next press down on LAlt and we see that AHK sends d signals for LCtrl (and again there is that 'ignored' u of LAlt on the second line which I wouldn't have expected), then I press down on LWin and AHK sends a d of LAlt and then I press down on SPACE:

A4  038 h   d   1.12    LAlt            
A4  038 i   u   0.00    LAlt            
A2  01D i   d   0.00    LControl        
5B  15B h   d   0.02    LWin            
A4  038 i   d   0.00    LAlt            
20  039     d   0.19    Space           

Finally comes the sequence where I release all those LAlt+LWin+SPACE and we see that AHK sends u signals for Space and LAlt and LCtrl:

20  039     u   0.06    Space           
5B  15B h   u   0.16    LWin            
A4  038 i   u   0.00    LAlt            
A4  038 h   u   0.00    LAlt            
A2  01D i   u   0.01    LControl        

Last is when I refresh the data in the AHK view window after having mouse-clicked to activate it:

74  03F     d   1.90    F5                  C:\...\AutoHotkey.ahk ...

That seems to prove that my AHK script has done what I hoped.

Only remaining issue is that mysterious u of an LAlt that cropped up twice.

Any ideas?

3
You can see which keys are being received in the [Key history and script info] view, but it doesn't show what it sends. [Lines most recently executed] is not perfect either.John Dvorak
Faced the same problem as you with GNU Emacs. Covered the issue and one of possible solutions on AHK Community forum.AntonLosev

3 Answers

4
votes

You can try using the Key History window

  • Run your hotkey script
  • Right click the tray icon and select Open
  • Click the View menu and select Key history and script info.

Key History screen

2
votes

Your question's title was, "Does Autohotkey have a test-my-script feature" - well, to answer just that, I suggest to use QuickAHK, which is designed to do just that! It has a sandbox, and lots of other features. I use it to test snippets all the time (I'm just a plain user - no affiliation with the program at all).

Here is the link to the current thread, because the old forum is defunct. and a current download link.

If you do a lot of quick-and-dirty script development or testing, you probably use a tool that allows you to run the script on the fly. These tools include a number of text editors, one of the tools posted on the AutoHotkey forum, or you've written your own. QuickAHK is another one of these tools... with a few differences:

  • Sandbox
  • Restore and Revert
  • stop scripts

However, there is also the QuickCodeTester, which is up-to-date and maintained.

1
votes

i use listlines followed by a pause at critical points the latest ahk also supports using debug statements OutputDebug, Text