help with key combination condition

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
kheerand
Posts: 2
Joined: 11 Jun 2018, 06:03

help with key combination condition

11 Jun 2018, 06:16

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
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: help with key combination condition

11 Jun 2018, 06:54

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
}
kheerand
Posts: 2
Joined: 11 Jun 2018, 06:03

Re: help with key combination condition

17 Jun 2018, 09:56

Thanks for you script swagfag. It didn't quite work. It still didn't caputure ^J + ^J and execute the send command. :(
User avatar
Cerberus
Posts: 172
Joined: 12 Jan 2016, 15:46

Re: help with key combination condition

17 Jun 2018, 20:48

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.)
Last edited by Cerberus on 18 Jun 2018, 19:29, edited 1 time in total.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: help with key combination condition

18 Jun 2018, 15:50

kheerand wrote:It didn't quite work. It still didn't caputure ^J + ^J and execute the send command. :(
it works for ^j + ^j

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 262 guests