Page 1 of 1

help with key combination condition

Posted: 11 Jun 2018, 06:16
by kheerand
Hi folks,

Somewhat of a newbie to AHK. I am trying to have the key combination of ^J followed by another key to take some action in a software application that I commonly use. The code I've got is,

Code: Select all

^j::
    input, command, L1, T1

    if (command = "^j" or command = "j")
    {
        send, ^d
        Sleep 10
        send, !s16
        send, !ct{enter}
    }
    else if (command = "2" or command = "k")
    {
        send, ^d
        Sleep 10
        send, !s14
        send, !ct{enter}
    }
    else if (command = "3" or command = "l")
    {
        send, ^d
        Sleep 10
        send, !s12
        send, !ct{enter}
    }
    ;send, {down}
Return
While this works for the key combination of ^j + 2 or ^j + k, it doesn't work for ^j + ^j. What am I doing wrong here?

Thank you in advance.

Regards
Kheeran

Re: help with key combination condition

Posted: 11 Jun 2018, 06:54
by swagfag
yeah idk if id necessarily use an input box for this:

Code: Select all

F1::ExitApp

^j::listenForNextKey := true
Esc::listenForNextKey := false ; premature cancel

#If listenForNextKey
j::
^j::
	sendSequence(16)
Return

2::
k::
	sendSequence(14)
Return

3::
l::
	sendSequence(12)
Return
#If

sendSequence(size)
{
	global listenForNextKey
	Send ^d
	Sleep 10
	Send % "!s" size "!ct{Enter}"
	listenForNextKey := false
}

Re: help with key combination condition

Posted: 17 Jun 2018, 09:56
by kheerand
Thanks for you script swagfag. It didn't quite work. It still didn't caputure ^J + ^J and execute the send command. :(

Re: help with key combination condition

Posted: 17 Jun 2018, 20:48
by Cerberus
The problem is that the second parameter after the Input command, the output variable (the parameter command, in your script), only outputs characters, not hotkeys that don't produce a (visible?) character. And ^j does not produce a character, it's just a hotkey. From the documentation:
OutputVar does not store keystrokes per se. Instead, it stores characters produced by keystrokes according to the active window's keyboard layout/language. Consequently, keystrokes that do not produce characters (such as PageUp and Home) are not stored (though they can be recognized via the EndKeys parameter below).
The proper command to use in your script would probably be the Hotkey command, to create temporary hotkeys, rather than the Input command. But it can still be done with the Input command if you use A_ThisHotkey instead of the output variable. This works for me:

Code: Select all

^j::
    input, command, L1 M T5

    if (A_Thishotkey = "^j" or command  = "j")
    {
        send, ^d
        Sleep 10
        send, !s16
        send, !ct{enter}
    }
    else if (command = "2" or command = "k")
    {
        send, ^d
        Sleep 10
        send, !s14
        send, !ct{enter}
    }
    else if (command = "3" or command = "l")
    {
        send, ^d
        Sleep 10
        send, !s12
        send, !ct{enter}
    }
    ;send, {down}
Return
I've also added the option M to the Input command, or it didn't work. Lastly, I've corrected an error in your code: T5 is an option just like L1 and M, and all options are one parameter together, so there shouldn't be a comma between any of them.

(I've also flagged this post to be moved to the "Ask for Help" forum.)

Re: help with key combination condition

Posted: 18 Jun 2018, 15:50
by swagfag
kheerand wrote:It didn't quite work. It still didn't caputure ^J + ^J and execute the send command. :(
it works for ^j + ^j