Page 1 of 1

Scripting help? Mouse position on screen=key press script?

Posted: Wed Apr 18, 2018 4:24 pm
by Canescj
Trying to figure out how to write a script that will do a key press when the mouse is, say within a square of points, on the screen. Any help would be appreciated.

Re: Scripting help? Mouse position on screen=key press scrip

Posted: Thu Apr 19, 2018 10:12 am
by FrenchyKiel
to trap x,y position of cursor, you could do that in python: (its not included in FreePie Mouse plugin)
you just test value of X and y and do an action to setkeypressed for example

Code: Select all

from ctypes import windll, Structure, c_long, byref
class POINT(Structure):
    _fields_ = [("x", c_long), ("y", c_long)]

def queryMousePosition():
    pt = POINT()
    windll.user32.GetCursorPos(byref(pt))
    return { "x": pt.x, "y": pt.y}

pos = queryMousePosition()
x = pos["x"]
y = pos["y"]
diagnostics.watch("x:" + str(x) + ", y:" + str(y))

Re: Scripting help? Mouse position on screen=key press scrip

Posted: Thu Apr 19, 2018 11:51 am
by Canescj
Yeah I have a grid program that tells you the x and y positions. My main issue is trying to figure out the getkeydown script. I've figured out how to activate a keypress when you go past a certain value of x and past a certain value of y but not a coordinate pair (x,y). And then a step past that would be figuring out how to only activate a keypress when the mouse is constrained between 4 specific points. Any ideas, because I'm kind of a noob when it comes to more complex scripts.

Re: Scripting help? Mouse position on screen=key press scrip

Posted: Thu Apr 19, 2018 1:00 pm
by FrenchyKiel
This code test if the mouse pointer is inside a square of 200x200 (top left)
it generates only one Keypress the Key.L
and when the key is pressed => speech OK

the flag inside avoid to have lot of L Pressed....

Code: Select all

from ctypes import windll, Structure, c_long, byref
class POINT(Structure):
    _fields_ = [("x", c_long), ("y", c_long)]

def queryMousePosition():
    pt = POINT()
    windll.user32.GetCursorPos(byref(pt))
    return { "x": pt.x, "y": pt.y}

pos = queryMousePosition()
x = pos["x"]
y = pos["y"]
diagnostics.watch("x:" + str(x) + ", y:" + str(y))


if  0 < x < 200 and 0 < y < 200:
	if inside == False:
		inside = True
		Keyboard.setPressed(Key.L)
else:
	inside = False

if Keyboard.getPressed(Key.L):
	speech.say("ok")

if starting:
	inside = False

Re: Scripting help? Mouse position on screen=key press scrip

Posted: Mon Apr 23, 2018 11:30 pm
by Canescj
It throws an exception; says setpressed and getpressed are undefined

Re: Scripting help? Mouse position on screen=key press scrip

Posted: Tue Apr 24, 2018 8:21 am
by FrenchyKiel
dont see error maybe, retype the function keyboard; dont do copy and paste