geekhack

geekhack Community => Keyboards => Topic started by: lorem3k on Sun, 10 June 2012, 16:42:15

Title: [AHK] Remapping {} and ()
Post by: lorem3k 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?
Title: [AHK] Remapping {} and ()
Post by: snowboarder3 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.
Title: [AHK] Remapping {} and ()
Post by: Soarer 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!
Title: [AHK] Remapping {} and ()
Post by: lorem3k 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 {}}