Force up key to be multi-function and shift

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
PCycle
Posts: 6
Joined: 17 May 2017, 23:26
Contact:

Force up key to be multi-function and shift

17 May 2017, 23:48

Hi All. I just got a new laptop that has made some weird layout choices and when I write, I constantly press the wrong keys. I could relearn how to type just for this keyboard but that isn't really my style :) I spend a few days with some luck trying to write this code but the closest I could get still had some major drawbacks so I just wanted to ask for help from you guys.

I want my UP key to work as RShift. But If I press it by itself I want it to be the UP key again. AND (this is the tricky part) When I hold the UP key I want the auto-repeat to work... or if you press the up key twice and hold it then that works as key repeat. And I need it to be normal if I am holding LShift and pressing up to select or un-select a body of text. I am doing some other modifications but I can handle all that, but this one needs a pro.

I had the most success using Keytweak to remap the key plus wrote a script, but when selecting text with RShift I had a big problem. Also I would prefer the whole thing be able to be turned on and off as I am only writing a fraction of the time and I may need to turn it off for games or daily use.

A Multifunction shift key is actually pretty brilliant. After you guys write this code, you could sell it to Lenovo. Check out the Lenovo 710 (11.6 inch) to see this keyboard layout.
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Force up key to be multi-function and shift

18 May 2017, 00:05

It's a shame.
lenovo-laptop-yoga-710-14-silver-keyboard-8.jpg
lenovo-laptop-yoga-710-14-silver-keyboard-8.jpg (149.38 KiB) Viewed 997 times
PCycle
Posts: 6
Joined: 17 May 2017, 23:26
Contact:

Re: Force up key to be multi-function and shift

22 May 2017, 13:17

Ok I got something working that any owner of this laptop should try out. Here is what it does. The shift key has been expanded to include the Up arrow and the /? key next to it. If you press any of those keys and press a left handed key it will give you the shift, but if you press it by itself, it will work like normal. The autorepeat on the up button will work if you press the up key twice within half a second and it will be unlocked for 20 seconds. Also the useless + button acts like backspace and the pointless - button does nothing (so that when I slap it meaning to hit backspace it doesn't cause an error but the - and _ characters can be activated using shift and control. This is my version 1.0. I need to make the code more streamline but this works and is a lifesaver so far.

There is a function upfront called rapidhotkeys that makes the double press functionality work. There is some useless code in here too.

#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.

RapidHotkey(keystroke, times="2", delay=0.2, IsLabel=0)
{
Pattern := Morse(delay*1000)
If (StrLen(Pattern) < 2 and Chr(Asc(times)) != "1")
Return
If (times = "" and InStr(keystroke, """"))
{
Loop, Parse, keystroke,""
If (StrLen(Pattern) = A_Index+1)
continue := A_Index, times := StrLen(Pattern)
}
Else if (RegExMatch(times, "^\d+$") and InStr(keystroke, """"))
{
Loop, Parse, keystroke,""
If (StrLen(Pattern) = A_Index+times-1)
times := StrLen(Pattern), continue := A_Index
}
Else if InStr(times, """")
{
Loop, Parse, times,""
If (StrLen(Pattern) = A_LoopField)
continue := A_Index, times := A_LoopField
}
Else if (times = "")
continue := 1, times := 2
Else if (times = StrLen(Pattern))
continue = 1
If !continue
Return
Loop, Parse, keystroke,""
If (continue = A_Index)
keystr := A_LoopField
Loop, Parse, IsLabel,""
If (continue = A_Index)
IsLabel := A_LoopField
hotkey := RegExReplace(A_ThisHotkey, "[\*\~\$\#\+\!\^]")
IfInString, hotkey, %A_Space%
StringTrimLeft, hotkey,hotkey,% InStr(hotkey,A_Space,1,0)
backspace := "{BS " times "}"
keywait = Ctrl|Alt|Shift|LWin|RWin
Loop, Parse, keywait, |
KeyWait, %A_LoopField%
If ((!IsLabel or (IsLabel and IsLabel(keystr))) and InStr(A_ThisHotkey, "~") and !RegExMatch(A_ThisHotkey
, "i)\^[^\!\d]|![^\d]|#|Control|Ctrl|LCtrl|RCtrl|Shift|RShift|LShift|RWin|LWin|Alt|LAlt|RAlt|Escape|BackSpace|F\d\d?|"
. "Insert|Esc|Escape|BS|Delete|Home|End|PgDn|PgUp|Up|Down|Left|Right|ScrollLock|CapsLock|NumLock|AppsKey|"
. "PrintScreen|CtrlDown|Pause|Break|Help|Sleep|Browser_Back|Browser_Forward|Browser_Refresh|Browser_Stop|"
. "Browser_Search|Browser_Favorites|Browser_Home|Volume_Mute|Volume_Down|Volume_Up|MButton|RButton|LButton|"
. "Media_Next|Media_Prev|Media_Stop|Media_Play_Pause|Launch_Mail|Launch_Media|Launch_App1|Launch_App2"))
Send % backspace
If (WinExist("AHK_class #32768") and hotkey = "RButton")
WinClose, AHK_class #32768
If !IsLabel
Send % keystr
else if IsLabel(keystr)
Gosub, %keystr%
Return
}
Morse(timeout = 400) { ;by Laszo -> http://www.autohotkey.com/forum/viewtopic.php?t=16951 (Modified to return: KeyWait %key%, T%tout%)
tout := timeout/1000
key := RegExReplace(A_ThisHotKey,"[\*\~\$\#\+\!\^]")
IfInString, key, %A_Space%
StringTrimLeft, key, key,% InStr(key,A_Space,1,0)
If Key in Shift,Win,Ctrl,Alt
key1:="{L" key "}{R" key "}"
Loop {
t := A_TickCount
KeyWait %key%, T%tout%
Pattern .= A_TickCount-t > timeout
If(ErrorLevel)
Return Pattern
If key in Capslock,LButton,RButton,MButton,ScrollLock,CapsLock,NumLock
KeyWait,%key%,T%tout% D
else if Asc(A_ThisHotkey)=36
KeyWait,%key%,T%tout% D
else
Input,pressed,T%tout% L1 V,{%key%}%key1%
If (ErrorLevel="Timeout" or ErrorLevel=1)
Return Pattern
else if (ErrorLevel="Max")
Return
}
}
$-::return
$=::
SendInput, {BS}
return

LShift & -::SendInput, -
CTRL & -::SendInput, _
#maxthreads

;keyhistory
GetKeyState, state, up
return
$Up up::SendInput, {Up}

$Up::RapidHotkey("test", 2, .5, 1) ;You Can also specify a Label to be launched

UP & a::sendInput, A
UP & 2::sendInput, @
UP & 3::sendInput, #
UP & 4::sendInput, $
UP & 5::sendInput, `%
UP & b::sendInput, B
UP & c::sendInput, C
UP & d::sendInput, D
UP & e::sendInput, E
UP & f::sendInput, F
UP & g::sendInput, G
UP & q::sendInput, Q
UP & w::sendInput, W
UP & r::sendInput, R
UP & t::sendInput, T
UP & s::sendInput, S
UP & z::sendInput, Z
UP & x::sendInput, X
UP & v::sendInput, V

/::

/ & 1::sendInput, !
/ & 2::sendInput, @
/ & 3::sendInput, #
/ & 4::sendInput, $
/ & 5::sendInput, `%
/ & a::sendInput, A
/ & b::sendInput, B
/ & c::sendInput, C
/ & d::sendInput, D
/ & e::sendInput, E
/ & f::sendInput, F
/ & g::sendInput, G
/ & q::sendInput, Q
/ & w::sendInput, W
/ & r::sendInput, R
/ & t::sendInput, T
/ & s::sendInput, S
/ & z::sendInput, Z
/ & x::sendInput, X
/ & v::sendInput, V
/ up::SendInput, /

test:
suspend, on
#usehook off




sleep, 20000
suspend, off

return










return
PCycle
Posts: 6
Joined: 17 May 2017, 23:26
Contact:

Re: Force up key to be multi-function and shift

24 May 2017, 19:21

This code works, but I would love it to be cleaner if possible. I'd rather have the up key auto repeat work again if you hold the key down long enough, like maybe 3/4 of a second, maybe if 1/2 a second. I would also love for shift + up to automatically break the hotkeys. Lastly I would love to use a shift command instead of explicitly typing out all the shifts. I just posted the code at this state cause I worked on it for like a week straight and I was just so happy to have something working. This shift concept that I created is straight genius though! Why not allow those two closer keys to act as shift hotkey, it doesn't hurt anything and allows you to work quick without thinking about how strangely cramped your keyboard is. If anyone is willing to help me with this code I would appreciate it, but I will write the code myself after my short break from it.

The reason I decided not to remap or tweak switch the shift and Up arrow is because I want to keys to work as expected when you are hunting and pecking. I'm not going to remember 3 months from now that I switched the layout and it's going to cause more problems. Why even as I type this, it works so flawlessly!
IMEime
Posts: 750
Joined: 20 Sep 2014, 06:15

Re: Force up key to be multi-function and shift

24 May 2017, 20:43

I'm sorry to say this, but for foregin language users like me, this board arrangement is a terrible terrible terrible disaster.
I must use right shift key all and every time.

Have a good time !!
PCycle
Posts: 6
Joined: 17 May 2017, 23:26
Contact:

Re: Force up key to be multi-function and shift

25 May 2017, 21:38

Well you can easily alter the code to make all the keys work with right shift but how does foreign language change the fact that the keyboard is two handed? When you capitalize the left hand keys you use right shift, when you capitalize the left hand keys, you use left shift. No? Color me confused. My girlfriend who is a weirdo always uses right shift too. Am I the only one who knows how to use shift?

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: NullRefEx, ShatterCoder and 108 guests