Overload Shift Keys for Programming? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
vawl
Posts: 9
Joined: 22 Jul 2017, 01:04

Overload Shift Keys for Programming?

22 Jul 2017, 02:01

Attempting to overload both Shift Keys to do the following:

LShift tapped:: - <--minus
LShift tapped-twice:: _ <--underscore

RShift tapped:: = <--equals sign
RShift tapped-twice:: + <--plus sign

Rshift+Lshift:: ( <--open parens
Lshift+Rshift:: ) <--closed parens


I've been using two scripts below, but I can't seem to modify them to play nice.

Code: Select all

*~LShift::
UserInput =
Input, UserInput, V L1
return
 
*LShift Up::
If UserInput = 
{
	Send % ""
	Send -
}
return
 
*~RShift::
UserInput =
Input, UserInput, V L1
return
 
 
*RShift Up::
If UserInput = 
{
	Send % ""
	Send {=}
}
return

;;;;;   ;;;               second script

; LShift + RShift
<+RShift:: )

; RShift + LShift
>+LShift:: (

;	2xLShift

~LShift::
If (A_PriorHotKey = "~LShift Up" AND A_TimeSincePriorHotkey < 200)
	send, {BackSpace}+_
return

~LShift Up:: Send, ^c{Shift Up} ;	copy

;	2xRShift

~RShift::
If (A_PriorHotKey = "~RShift Up" AND A_TimeSincePriorHotkey < 200)
	send {BackSpace}+{+}
return

~RShift Up:: Send,{Shift Up}

User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Overload Shift Keys for Programming?  Topic is solved

22 Jul 2017, 08:03

How's this:

Code: Select all

*~LShift::
*~RShift::
	PriorPriorKey:=A_Priorkey
Return

*~LShift up::
*~RShift up::
	If (A_Thishotkey="*~LShift up")
		Key:=["-","_","(","LShift","RShift"]
	else
		Key:=["=","{+}",")","RShift","LShift"]
	
	If (A_Priorkey=Key[4]){
		If GetKeyState(Key[5],"P")
			Send % Key[3]
		Else If (PriorPriorKey=Key[4] && TimeSincePriorShift[Key[4]] && (A_TickCount-TimeSincePriorShift[Key[4]])<200){
			Send % "+{Left}" Key[2]
			TimeSincePriorShift[Key[4]]:=""
			Return
		}Else 
			Send % Key[1]
	}
	TimeSincePriorShift:={Key[4]:A_TickCount}
Return
vawl
Posts: 9
Joined: 22 Jul 2017, 01:04

Re: Overload Shift Keys for Programming?

22 Jul 2017, 20:15

I am unworthy, sir Nextron. This is taking my breath away thus far.
User avatar
Nextron
Posts: 1391
Joined: 01 Oct 2013, 08:23
Location: Netherlands OS: Win10 AHK: Unicode x32

Re: Overload Shift Keys for Programming?

22 Jul 2017, 20:57

Haha, glad you like it. :thumbup:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 247 guests