Multiple Keys with GetKeyState (?)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
daniaparecido
Posts: 3
Joined: 02 Oct 2021, 14:53

Multiple Keys with GetKeyState (?)

Post by daniaparecido » 09 Oct 2021, 13:16

Code: Select all

#NoEnv
#IfWinActive, Adobe Premiere Pro 2021
#SingleInstance force
#WinActivateForce 
#MaxHotkeysPerInterval 2000
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
Menu, Tray, Icon, imageres.dll, 82


SetWorkingDir, D:\@ Edição de Vídeo\AHS Working Dir\

#IfWinActive ahk_exe Adobe Premiere Pro.exe

~F14:: 
global VFXkey = "F14"
instantVFX("scale")
return

#IfWinActive ahk_exe Adobe Premiere Pro.exe
~F15::
global VFXkey = "F15"
instantVFX("anchor_point_vertical")
return

#IfWinActive ahk_exe Adobe Premiere Pro.exe
~F17::
global VFXkey = "F17"
instantVFX("rotation")
return

#IfWinActive ahk_exe Adobe Premiere Pro.exe
~F18::
global VFXkey = "F18"
instantVFX("anchor_point")
return




clickTransformIcon()
{
ControlGetPos, Xcorner, Ycorner, Width, Height, DroverLord - Window Class10, ahk_class Premiere Pro 
MouseMove, Xcorner+99, Ycorner+99, 0 

MouseClick, left
}




instantVFX(foobar)

{
dontrestart = 0
restartPoint:
blockinput, sendandMouse
blockinput, MouseMove
blockinput, on
Sendinput ^!+5
sleep 10


MouseGetPos Xbeginlol, Ybeginlol
global Xbegin = Xbeginlol
global Ybegin = Ybeginlol

ControlGetPos, Xcorner, Ycorner, Width, Height, DroverLord - Window Class10, ahk_class Premiere Pro



YY := Ycorner+99
XX := Xcorner+18
MouseMove, XX, YY, 0
sleep 10

PixelGetColor, colorr, XX, YY

if (colorr = "0x979797")
{
	
	blockinput, Mouse
	Click XX, YY
	sleep 5
	clickTransformIcon()
	findVFX(foobar)
	Return
}
else if (colorr = "0x7A7A7A") 
{
	
	blockinput, Mouse
	sleep 5
	clickTransformIcon()
	findVFX(foobar)
	;untwirled = 1
	Return, untwirled
}
else if (colorr = "0x1D1D1D" || colorr = "0x232323")
	{
	
	Send ^p 
	sleep 10
	Send ^p  
	resetFromAutoVFX()
	
	If (dontrestart = 0)
		{
		dontrestart = 1
		goto, restartPoint 
		}
	Return reset
	}
else
	{
	tooltip, %colorr% not expected
	
	resetFromAutoVFX()
	Return reset
	}
}
Return 




findVFX(foobar) 
{

sleep 5
MouseGetPos xPos, yPos


/*
if foobar = "scale"
	ImageSearch, FoundX, FoundY, xPos-90, yPos, xPos+800, yPos+500, %A_WorkingDir%\scale_D2021.png
else if foobar = "anchor_point"
	ImageSearch, FoundX, FoundY, xPos-90, yPos, xPos+800, yPos+500, %A_WorkingDir%\anchor_point_D2021.png
*/

ImageSearch, FoundX, FoundY, xPos-90, yPos, xPos+800, yPos+900, %A_WorkingDir%\%foobar%_D2021.png

if ErrorLevel = 1
	ImageSearch, FoundX, FoundY, xPos-30, yPos, xPos+1200, yPos+1200, *10 %A_WorkingDir%\%foobar%_D2021.png 

if ErrorLevel = 2
	{
    msgbox,,, ERROR LEVEL 2`nCould not conduct the search,1
	resetFromAutoVFX()
	}
if ErrorLevel = 1
	{
	;msgbox, , , error level 1, .7
    msgbox,,, ERROR LEVEL 1`n%foobar% could not be found on the screeen,1
	resetFromAutoVFX()
	}
else
	{
	
	MouseMove, FoundX, FoundY, 0
	
	sleep 5
	findHotText(foobar)
	}
}


findHotText(foobar)


{
tooltip, 

MouseGetPos, xxx, yyy

if (foobar = "scale" ||  foobar = "anchor_point" || foobar = "rotation")
{
	
	PixelSearch, Px, Py, xxx+50, yyy+10, xxx+500, yyy+11, 0x3398EE, 30, Fast RGB 
}
else if (foobar = "anchor_point_vertical")
{
	
	ImageSearch, Px, Py, xxx+100, yyy, xxx+800, yyy+100, %A_WorkingDir%\anti-flicker-filter_000.png 
}



if ErrorLevel
	{
    
	sleep 100
	resetFromAutoVFX()
	
	}
else
	{
	
	if (foobar <> "anchor_point_vertical")
	{
		
		MouseMove, Px+10, Py+5, 0 
	}
	else if (foobar = "anchor_point_vertical")
	{
		MouseMove, Px+80, Py-20, 0 
		tooltip, where am I?
		
	}
	Click down left
	
	GetKeyState, stateFirstCheck, %VFXkey% , "P"
		
	if stateFirstCheck = U
		{
			
			Click up left
			Sleep 10
			if (foobar = "scale")
			{
				Send, 100
				sleep 50
				Send, {enter} 
				sleep 20
			}
			if (foobar = "rotation")
			{
				Send, 0
				sleep 50
				Send, {enter} 
				sleep 20
			}
			resetFromAutoVFX()
			
		}
	
	Loop
		{
		blockinput, off
		blockinput, MouseMoveOff
		
		tooltip, 
		sleep 15
		GetKeyState, state, %VFXkey% , "P"
		if state = U
			{
			Click up left
			
			sleep 15
			resetFromAutoVFX()
			
			Return
			}
		}
	}
}

resetFromAutoVFX()
{

	global Xbegin
	global Ybegin
	MouseMove, Xbegin, Ybegin, 0

	blockinput, off
	blockinput, MouseMoveOff

}

I have this code that I ~stole~ from Taran Van Hermert (TaranVH) that only works if I define %VFXkey% to a single keystroke. I want to be able to call this function with two keystrokes, such as "Shift+S" to call the %foobar% = "scale", for example. I want to be able to assign this function to happen when I press two keystrokes (such as "Shift+S") because I don't have any other single keystrokes left to assign.

My plan is to use Shift and %VFXkey% to activate each string of the instantVFX() function.

Basically what this script does is:

1. Get your XY position of your mouse (so that it can return to it original position at the end)

2. Find a particular window class in Premiere Pro (video editing software) to then find a particular parameter that I want to change, basically by moving the mouse to the value of the specified parameter. So when I press the assigned keystroke, it will click and hold the left mouse button until I release the key.

I think this is able to happen, because at the end of the function exists two GetKeyState that identifies when the key is released by defining an "if" statement in which specifies a state of the GetKeyState to be "U", one leading to Loop and other leading to reset the parameter value to default (inside Premiere Pro).

But I don't have a clue about how to make this GetKeyState work with two keystrokes.
Tried simpler solutions, like:


Defining Shift+S to be the %VFXkey% and the macro to call.

Code: Select all

+s::
global VFXkey = "Shift & S"
instantVFX("scale")
return

Defining Shift+S to be F14

Code: Select all

+s::F14

F14::
global VFXkey = "F14"
instantVFX("scale")
return
Defining the %VFXkey% to be "S", then using GetKeyState to get "S" and "Shift" and using "if" to send "S" only if "Shift" is held.

Code: Select all

Shift::
GetKeyState("S","P")
shift := GetKeyState("LSHIFT","P")
    if shift { 

send s

}

else {

return,

}

+s::
global VFXkey = "S"
instantVFX("scale")
return
Inside the function, add another GetKeyState to include "Shift"

Code: Select all

    GetKeyState, stateFirstCheck, %VFXkey%, P
    GetKeyState, stateFirstCheck, Shift, P
        
    if stateFirstCheck = U

    [...]
Unfortunately none of this worked, I'd be very glad if someone could help me, it is a very important function for me to work. Tried to describe best as possible 🙂

There's the video of TaranVH explaining and showing how this works:
https://youtu.be/Bi3zBqO74ms

colt
Posts: 291
Joined: 04 Aug 2014, 23:12
Location: Portland Oregon

Re: Multiple Keys with GetKeyState (?)

Post by colt » 09 Oct 2021, 16:06

I would replace the getkeystate lines with a custom function.
try replacing the lines inside instantVFX(foobar)

Code: Select all

GetKeyState, stateFirstCheck, %VFXkey% , "P"
with

Code: Select all

stateFirstCheck := getKeyComboState(VFXkey)
and

Code: Select all

GetKeyState, state, %VFXkey% , "P"
with

Code: Select all

state:= getKeyComboState(VFXkey)
paste the getKeyComboState function at the end of your script

Here is example usage of this function with single, double & triple key combos

Code: Select all

#NoEnv
#SingleInstance Force
SetBatchLines -1

+s::
global VFXkey = "Shift&S"
instantVFX("scale")
return

^+s::
global VFXkey = "Control&Shift&S"
instantVFX("scale")
return

f8::
global VFXkey = "F8"
instantVFX("scale")
return


instantVFX(foobar) ;example dummy function
{	
	loop
	{
		state := getKeyComboState(VFXkey)
		tooltip % VFXkey . "`n" . state 
		if(state == "U")
		{
			break
		}
	}
}

getKeyComboState(keyCombo)
{
	keys := strSplit(keyCombo,"&") ;creates array that contains your pressed keys using "&" as delimeter
	for index,key in keys
	{	
		;msgbox % key	
		if(!getKeystate(key,"P")) ;check the physical state of each key in your combo
		{
			return "U" ;at least one of your keys was up so return "U"
 			break
		}
	}
	return "P" ;all keys in your combo are pressed so return "P"
}

Post Reply

Return to “Ask for Help (v1)”