1

I'm trying to replicate TouchCursor keys using AutoHotkey, but I can't get it to work with multiple modifiers.

This is what I have so far (from https://autohotkey.com/boards/viewtopic.php?t=6525):

space & g::Send, {esc}
space & l::send, {right}
space & k::send, {up}
space & j::send, {down}
space & h::send, {left}
space & p::send, {backspace}
space & m::send, {delete}
space & u::send, {home}
space & o::send, {end}
space::
Send, {space}
return

The above script works fine to move the cursor around using 'h', 'j', 'k', and 'l', but it's ignoring control and shift keys.

For example, I was expecting to highlight letters using space+shift+h to highlight left similar to space+shift+left arrow.

I tried: +space & h::send, {left} and got the following error:

enter image description here

EDIT

This script will work with control and shift:

; Right, Shift+Right, Control+Right, Shift+Control+Right
space & l::
    if((GetKeyState("Shift", "P") and (GetKeyState("Control", "P")))) {
        send, +^{right}
    } else if(GetKeyState("Shift", "P")) {
        send, +{right}
    } else if(GetKeyState("Control", "P")) {
        send, ^{right}
    } else {
        send, {right}
    }
Return

; Up, Shift+Up, Control+Up, Shift+Control+Up
space & k::
    if((GetKeyState("Shift", "P") and (GetKeyState("Control", "P")))) {
        send, +^{up}
    } else if(GetKeyState("Shift", "P")) {
        send, +{up}
    } else if(GetKeyState("Control", "P")) {
        send, ^{up}
    } else {
        send, {up}
    }
Return

; Down, Shift+Down, Control+Down, Shift+Control+Down
space & j::
    if((GetKeyState("Shift", "P") and (GetKeyState("Control", "P")))) {
        send, +^{down}
    } else if(GetKeyState("Shift", "P")) {
        send, +{down}
    } else if(GetKeyState("Control", "P")) {
        send, ^{down}
    } else {
        send, {down}
    }
Return

; Left, Shift+Left, Control+Left, Shift+Control+Left
space & h::
    if((GetKeyState("Shift", "P") and (GetKeyState("Control", "P")))) {
        send, +^{left}
    } else if(GetKeyState("Shift", "P")) {
        send, +{left}
    } else if(GetKeyState("Control", "P")) {
        send, ^{left}
    } else {
        send, {left}
    }
Return

; Home, Shift+Home, Control+Home, Shift+Control+Home
space & u::
    if((GetKeyState("Shift", "P") and (GetKeyState("Control", "P")))) {
        send, +^{home}
    } else if(GetKeyState("Shift", "P")) {
        send, +{home}
    } else if(GetKeyState("Control", "P")) {
        send, ^{home}
    } else {
        send, {home}
    }
Return

; End, Shift+End, Control+End, Shift+Control+End
space & o::
    if((GetKeyState("Shift", "P") and (GetKeyState("Control", "P")))) {
        send, +^{end}
    } else if(GetKeyState("Shift", "P")) {
        send, +{end}
    } else if(GetKeyState("Control", "P")) {
        send, ^{end}
    } else {
        send, {end}
    }
Return

; Backspace, Shift+Backspace
space & p::
    if(GetKeyState("Control", "P")) {
        send, ^{backspace}
    } else {
        send, {backspace}
    }
Return

; Simple modifiers
space & g::Send, {esc} 
space & m::send, {delete}

; Allow space bar to go through if pressed without holding
space::
Send, {space}
return

1 Answer 1

2

You will need to use an if statement with the GetKeyState function to capture the extra modifiers. Specifically to find the P (Physical state) of the shift modifier.

For example, the space & h combination:

space & h::
    if(GetKeyState("Shift", "P")) {
        send, +{left}
    } else {
        send, {left}
    }
Return

I suspect you will probably go a step further and want to implement the ctrl modifier as well. You would need to expand upon the if statement and be careful of the way the if statement executes.

space & h::
    if((GetKeyState("Shift", "P") and (GetKeyState("Control", "P")))) {
        send, +^{left}
    } else if(GetKeyState("Shift", "P")) {
        send, +{left}
    } else if(GetKeyState("Control", "P")) {
        send, ^{left}
    } else {
        send, {left}
    }
Return

You need to check the key states of Shift and Control first, and then the individual modifiers otherwise it would exit too early and only execute one of the modifiers.

2
  • Thanks this is exactly what I need. I will post the complete script to the question.
    – Timber
    Jan 30, 2017 at 17:36
  • You can also use #If directives to create context-sensitive hotkeys (Hotkey variants with #If criteria always have precedence).
    – Relax
    Jan 30, 2017 at 17:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .