Scripting help? Mouse position on screen=key press script?
-
- One Eyed Hopeful
- Posts: 21
- Joined: Thu Oct 19, 2017 6:14 pm
Scripting help? Mouse position on screen=key press script?
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.
-
- One Eyed Hopeful
- Posts: 47
- Joined: Thu Oct 03, 2013 7:10 am
Re: Scripting help? Mouse position on screen=key press scrip
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
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))
-
- One Eyed Hopeful
- Posts: 21
- Joined: Thu Oct 19, 2017 6:14 pm
Re: Scripting help? Mouse position on screen=key press scrip
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.
-
- One Eyed Hopeful
- Posts: 47
- Joined: Thu Oct 03, 2013 7:10 am
Re: Scripting help? Mouse position on screen=key press scrip
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....
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
-
- One Eyed Hopeful
- Posts: 21
- Joined: Thu Oct 19, 2017 6:14 pm
Re: Scripting help? Mouse position on screen=key press scrip
It throws an exception; says setpressed and getpressed are undefined
-
- One Eyed Hopeful
- Posts: 47
- Joined: Thu Oct 03, 2013 7:10 am
Re: Scripting help? Mouse position on screen=key press scrip
dont see error maybe, retype the function keyboard; dont do copy and paste