Author Topic: [AHK] Remapping {} and ()  (Read 3557 times)

0 Members and 1 Guest are viewing this topic.

Offline lorem3k

  • Thread Starter
  • Posts: 128
    • http://twitter.com/#!/lorem3k
[AHK] Remapping {} and ()
« on: Sun, 10 June 2012, 16:42:15 »
I'm trying to swap the curly braces with the parentheses, so that when I hold shift and press on one of the square bracket keys, it gives me the corresponding parenthesis, and when I hold shift and press 9 or 0, I get the curly braces. This is what I have in AutoHotKey right now:
Code: [Select]
+[::SendInput {(}
+]::SendInput {)}
+9::SendInput {{}
+0::SendInput {}}


When I run this code and hold shift while pressing the square brackets, it gives me the error:
Code: [Select]
71 hotkeys have been received in the last 0ms.

Do you want to continue?


Does anybody know what's wrong with my code?
Leopold FC200RT/AWN | Logitech G400 | Sennheiser HD25-1 II | Pounds in the fridge, hundred stacks in the armoire

Offline snowboarder3

  • Posts: 316
[AHK] Remapping {} and ()
« Reply #1 on: Sun, 10 June 2012, 17:14:18 »
Code: [Select]
{::(
}::)
(::{
)::}


not entirely sure, but sendinput seems to be throwing it into a loop. so pressing { causes the press of (, which is mapped to { and thus you get an infinite loop. The AHK program sets a limit to stop things like this from occurring.

Offline Soarer

  • * Elevated Elder
  • Posts: 1918
  • Location: UK
[AHK] Remapping {} and ()
« Reply #2 on: Sun, 10 June 2012, 18:20:02 »
I did something similar, where I swapped the shift state on all the number row keys and the [ and ] keys...

Code: [Select]
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
#SingleInstance Force
#HotkeyInterval 999999
#MaxHotkeysPerInterval 9999
#UseHook On

;$+1::
;if GetKeyState("Capslock", "T")
; Send +1
;else
; Send 1
;return

+1::Send 1
1::Send +1

+2::Send 2
2::Send +2

+3::Send 3
; 3 -> '+'
3::Send +{SC00D}
; AltGr 3 -> '£'
;<^>!3::Send +3
<^>!3::Send {ASC 156}

+4::Send 4
4::Send +4

+5::Send 5
5::Send +5

+6::Send 6
6::Send +6

+7::Send 7
7::Send +7

+8::Send 8
8::Send +8

+9::Send 9
9::Send +9

+0::Send 0
0::Send +0

; '['
SC01A::Send +{SC01A}
+SC01A::Send {SC01A}

; ']'
SC01B::Send +{SC01B}
+SC01B::Send {SC01B}

One difference is that I sent e.g. +4 instead of $, and also for swapping the [ and { I used scan codes instead - sorry, but I can't remember exactly why I did that now!

Offline lorem3k

  • Thread Starter
  • Posts: 128
    • http://twitter.com/#!/lorem3k
[AHK] Remapping {} and ()
« Reply #3 on: Sun, 10 June 2012, 21:15:32 »
Thanks for posting your code, Soarer. I got it to work using the scan codes.
Code: [Select]
; '['
+SC01A::Send {(}

; ']'
+SC01B::Send {)}

; '9'
+SC00A::Send {{}

; '0'
+SC00B::Send {}}
Leopold FC200RT/AWN | Logitech G400 | Sennheiser HD25-1 II | Pounds in the fridge, hundred stacks in the armoire