How to bond hotstring to direction keys? Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
pk23
Posts: 67
Joined: 24 Apr 2015, 00:49

How to bond hotstring to direction keys?

03 Mar 2017, 23:32

I need to achieve something like this:

Code: Select all

::{Left}{Right}:: SendInput, ^ + {Right}
Why don't I use normal hotkey?
Because using direction key as a modifier, there's so many side effects, such as 'long press Left', 'hold down Shift and press Left'...finally have to deal with these trouble.

So...can the arrow keys trigger the hot string?
Helgef
Posts: 4182
Joined: 17 Jul 2016, 01:02
Contact:

Re: How to bond hotstring to direction keys?

03 Mar 2017, 23:44

You could try to use Input.
Edit, you can make a context sensitive hotkey using A_priorkey, eg,

Code: Select all

#if a_priorkey="left"
Right::^right
pk23
Posts: 67
Joined: 24 Apr 2015, 00:49

Re: How to bond hotstring to direction keys?

04 Mar 2017, 00:29

Helgef wrote:
I tried
~Left::
Input, UserInput, V T5 L4 C, , {Right} ; or just Right without bracket
 if ErrorLevel = Match
  Send, success
 return
Seems not working.
However, a_priorkey works! Thank you so so much! :dance: :thumbup:
pk23
Posts: 67
Joined: 24 Apr 2015, 00:49

Re: How to bond hotstring to direction keys?

04 Mar 2017, 01:53

Helgef wrote:
Sorry to ask help again, but I get stuck. I want to send something after "press LEFT then RIGHT", and send another something after "press RIGHT then LEFT".
I tried to code like this:

Code: Select all

	#If a_priorkey = "left" and A_TimeSincePriorHotkey < 1000
		Right:: 
			SendInput, ^+{right}
			;MsgBox, %A_TimeSinceThisHotkey%
			return
	#If a_priorkey = "right" and A_TimeSincePriorHotkey < 1000
		Left:: 
			SendInput, ^+{left}
			;MsgBox, %A_TimeSinceThisHotkey%
			return
However, both shortcut key only effective in the first time, and not effect after.
Why? I also tried A_TimeIdle and A_TimeSinceThisHotkey, or use modifier like $ and ~, which is more not what I need...
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
GitHub: 4GForce

Re: How to bond hotstring to direction keys?

04 Mar 2017, 05:53

pk23 wrote:Why? I also tried A_TimeIdle and A_TimeSinceThisHotkey, or use modifier like $ and ~, which is more not what I need...
You sure ? Works fine with A_TimeSinceThisHotkey.

Code: Select all

#If a_priorkey = "left" and A_TimeSinceThisHotkey < 1000
	Right:: 
		; SendInput, ^+{right}
		MsgBox, % "left right"
	return
#If
#If a_priorkey = "right" and A_TimeSinceThisHotkey < 1000
	Left:: 
		; SendInput, ^+{left}
		MsgBox, % "right left"
	return
#If
pk23
Posts: 67
Joined: 24 Apr 2015, 00:49

Re: How to bond hotstring to direction keys?

04 Mar 2017, 06:20

4GForce wrote:You sure ? Works fine with A_TimeSinceThisHotkey.
You can use notepad, paste anything to it, and try test with original 'SendInput, ^+{right}', not 'MsgBox, % "left right"', to see what happens.
Press left and right first, wait 5 seconds, and press left and right again.
see, does it run as what you expect?

btw: In the scene where I encountered this problem, I had solved it in other ways. However, the problem itself, seems interesting.
Next time similar problem happens, is there any ways to solve it satisfactorily?
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
GitHub: 4GForce

Re: How to bond hotstring to direction keys?

04 Mar 2017, 06:37

pk23 wrote:Press left and right first, wait 5 seconds, and press left and right again.
see, does it run as what you expect?
Still working fine !
pk23
Posts: 67
Joined: 24 Apr 2015, 00:49

Re: How to bond hotstring to direction keys?

04 Mar 2017, 07:09

4GForce wrote:Still working fine !
Thanks for test, that's wierd...In my PC:
Image
4GForce
Posts: 553
Joined: 25 Jan 2017, 03:18
GitHub: 4GForce

Re: How to bond hotstring to direction keys?  Topic is solved

04 Mar 2017, 07:45

pk23 wrote:
4GForce wrote:Still working fine !
Thanks for test, that's wierd...In my PC:
I might have tested too fast ... this seems to work better ...

Code: Select all

#singleinstance force

Right:: 
	if(A_Priorkey = "Left" AND A_TimeSincePriorHotKey < 1000) {
		Send ^+{Right}
		; MsgBox, % "left right"
	}
	else {
		Send {Right}
	}
return

Left::
	if(A_Priorkey = "Right" AND A_TimeSincePriorHotKey < 1000) {
		Send ^+{Left}
		; MsgBox, % "right left"
	}
	else {
		Send {Left}
	}
return


; 5555555555
pk23
Posts: 67
Joined: 24 Apr 2015, 00:49

Re: How to bond hotstring to direction keys?

04 Mar 2017, 08:20

4GForce wrote:I might have tested too fast ... this seems to work better ...

Code: Select all

#singleinstance force

Right:: 
	if(A_Priorkey = "Left" AND A_TimeSincePriorHotKey < 1000) {
		Send ^+{Right}
		; MsgBox, % "left right"
	}
	else {
		Send {Right}
	}
return

Left::
	if(A_Priorkey = "Right" AND A_TimeSincePriorHotKey < 1000) {
		Send ^+{Left}
		; MsgBox, % "right left"
	}
	else {
		Send {Left}
	}
return


; 5555555555
It works, and clever solution. :dance:
emm, then a mysterious question for me is, why the script given in floor 4 not work? because based on definiton of A_TimeSincePriorHotkey, it SHOULD work. Just curious... :think:

Return to “Ask For Help”

Who is online

Users browsing this forum: akaza_dorian, Google [Bot], NaNoMister, SashaChernykh, Scr1pter and 391 guests