2

Similar to what this question covers, I'm trying to bind two sequences of keys.

Ideally I'd like to bind Alt DOWN,-,-,-,Alt UP to an em-dash (—) and Alt DOWN,-,-,Alt UP to an en-dash (–).

What I have almost works for em-dashes but not quite:

; Em-dash
!-::
Input Key, L1
if Key=-
Input Key, L1
if Key=-
Send {ASC 0151}
return 

; En-dash
;!-::
;Input Key, L1
;if Key=-
;Send {ASC 0150}
;return

The em-dash sequence works like Alt+-,-,-, instead of what I'm trying to match. I'm not sure how to only test for Alt DOWN and Alt UP. The en-dash sequence fails altogether to bind because !- has already been bound.

Community
  • 1
  • 1
travis
  • 35,751
  • 21
  • 71
  • 94
  • Is there any particular reason why you don't want to use [hotstrings](http://www.autohotkey.com/docs/Hotstrings.htm)? For instance, make typing `---` convert to em-dash, and `--` convert to en-dash. – Elliot DeNolf Jul 17 '14 at 20:22
  • @ElliotDeNolf I often use `--` in programming. – travis Jul 17 '14 at 20:35

1 Answers1

6

Have a look at this one:

dashCount := 0

!-::
    dashCount++
    if(dashCount = 1) {
        SetTimer, WaitForAlt, -1
    }
return

WaitForAlt:
    KeyWait, Alt
    if(dashCount = 2) {
        Send {ASC 0150}
    } else if(dashCount = 3) {
        Send {ASC 0151}
    }
    dashCount := 0
return

It seems to do the job well. The code works by counting each time Alt + - gets pressed. Concurrently, a pseudo-thread is spawned that waits for Alt to be released and then sends the appropriate dash, depending on the counter.

MCL
  • 3,985
  • 3
  • 27
  • 39
  • That works great! Is there API documentation on `SetTimer` or `KeyWait`? Google always returns forum posts from years ago that aren't very helpful. – travis Jul 18 '14 at 14:23
  • @travis I just read that you want to avoid hotstrings since they would be triggered when using the decrement operator. Did you know that you can make context-sensitive hotstrings using `#If` or `#IfWin...`? – MCL Jul 20 '14 at 08:47
  • I program with and need the dashes in the same apps, unfortunately. – travis Jul 21 '14 at 17:59