Get last key press

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
goksel
Posts: 7
Joined: 11 Dec 2018, 22:14

Get last key press

11 Dec 2018, 22:27

Hi, I need a script for this (exclude mouse clicks for last key press):

Code: Select all

click q :: 
   if last key was number 1 , do {q Up}{q Down}{Ctrl Up}1{Ctrl Down}
   else if last key was number 2 , {q Up}{q Down}{Ctrl Up}2{Ctrl Down}
   else q
end
So basically, when I press q, and last key pressed was 1, I want this 3 button combination :

Code: Select all

{q Up}{q Down}{Ctrl Up}1{Ctrl Down}
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Get last key press

11 Dec 2018, 22:41

A_PriorKey
goksel
Posts: 7
Joined: 11 Dec 2018, 22:14

Re: Get last key press

12 Dec 2018, 06:55

I tried with a_priorkey but Is there a way to ignore mouse clicks
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Get last key press

12 Dec 2018, 10:24

either make sure no mouse hooks ever get installed, or else ud have to keep track of it urself:

Code: Select all

#InstallKeybdHook
#InstallMouseHook

~*LButton::
~*RButton::
~*MButton::
~*XButton1::
~*XButton2::
~*WheelUp::
~*WheelDown::
~*WheelLeft::
~*WheelRight::
	if !(A_PriorKey ~= "[LRMX]Button\d?|Wheel(Up|Down|Left|Right)")
		lastKeyboardKey := A_PriorKey
return

q::
	if !lastKeyboardKey
		lastKeyboardKey := A_PriorKey

	if (lastKeyboardKey ~= "[1-9]")
		Send {q Up}{q Down}{Ctrl Up}%lastKeyboardKey%{Ctrl Down}

	lastKeyboardKey := ""
Return
goksel
Posts: 7
Joined: 11 Dec 2018, 22:14

Re: Get last key press

12 Dec 2018, 13:14

swagfag wrote:
12 Dec 2018, 10:24
either make sure no mouse hooks ever get installed, or else ud have to keep track of it urself:

Code: Select all

#InstallKeybdHook
#InstallMouseHook

~*LButton::
~*RButton::
~*MButton::
~*XButton1::
~*XButton2::
~*WheelUp::
~*WheelDown::
~*WheelLeft::
~*WheelRight::
	if !(A_PriorKey ~= "[LRMX]Button\d?|Wheel(Up|Down|Left|Right)")
		lastKeyboardKey := A_PriorKey
return

q::
	if !lastKeyboardKey
		lastKeyboardKey := A_PriorKey

	if (lastKeyboardKey ~= "[1-9]")
		Send {q Up}{q Down}{Ctrl Up}%lastKeyboardKey%{Ctrl Down}

	lastKeyboardKey := ""
Return
I will test this tonight. Thanks!
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Get last key press

12 Dec 2018, 13:23

what are u talking about? thats exactly what A_PriorKey does
goksel
Posts: 7
Joined: 11 Dec 2018, 22:14

Re: Get last key press

12 Dec 2018, 21:01

swagfag wrote:
12 Dec 2018, 10:24
either make sure no mouse hooks ever get installed, or else ud have to keep track of it urself:

Code: Select all

#InstallKeybdHook
#InstallMouseHook

~*LButton::
~*RButton::
~*MButton::
~*XButton1::
~*XButton2::
~*WheelUp::
~*WheelDown::
~*WheelLeft::
~*WheelRight::
	if !(A_PriorKey ~= "[LRMX]Button\d?|Wheel(Up|Down|Left|Right)")
		lastKeyboardKey := A_PriorKey
return

q::
	if !lastKeyboardKey
		lastKeyboardKey := A_PriorKey

	if (lastKeyboardKey ~= "[1-9]")
		Send {q Up}{q Down}{Ctrl Up}%lastKeyboardKey%{Ctrl Down}

	lastKeyboardKey := ""
Return
It works like a charm!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Chunjee, Giresharu, inseption86, KruschenZ, mikeyww, Swiftly9767 and 291 guests