Is there a way to move a mouse to exact coordinates using CircuitPython? - hid

I am using a Raspberry Pi Pico to move my mouse to an absolute position on a button press. However, I have noticed mouse.move moves your current mouse position by x and y units, but I want to change my mouse position to be exact and not based on the current position. Is there a way to dot his

Related

How can I detect the mouse position anywhere on the screen?

I'm working in MATLAB and I want to get the cursor position from anywhere on the screen.
I would like to continuously get the position of the cursor while the mouse is moving. However, I found that MATLAB can get the mouse position while the mouse is moving only in a GUI.
How can I achieve the same thing but not in a GUI in MATLAB?
Are you sure MATLAB can only get the mouse co-ordinates within a GUI? It's actually quite simple to get the position of your mouse anywhere on your screen, independent of a GUI.
Use the following:
get(0, 'PointerLocation')
Try this by moving your mouse around and invoking this command each time. You will see that the output keeps changing when the mouse moves. You'll see that this works independent of a GUI.
The output of this function will return a two-element array where the first element is the x or column position and the second element is the y or row position of your mouse. Bear in mind that the reference point is with respect to the bottom left corner of your screen. As such, placing your mouse at the bottom left corner of the screen should yield (1,1) while placing your mouse at the top right corner of the screen yields the resolution of your screen.
Now, if you want to continuously get the position of the mouse, consider placing this call in a while loop while pausing for a small amount of time so you don't overload the CPU. Therefore, do something like this:
while condition
loc = get(0, 'PointerLocation');
%// Do something
%...
%...
pause(0.01); %// Pause for 0.01 ms
end

Autohotkey - Remap mouse wheel when mouse touch edge of screen

I want to remap mouse wheel down to Ctrl+Alt+E but only when the mouse touches the right edge of the screen. I know how to remap the mouse wheel scroll but i don't know how to make it work only when the mouse touch the edge of the screen:
WheelDown::^!e
I hope someone can help me with the rest of the script.
Consider this, if you mean touching the right edge, it means that the X coordinate of the mouse is equal the maximum usually, the screen's width (±1 pixel).
#If can be used to create context-sensitive hotkeys. See #If
A_ScreenWidth can be used to get the screen's width. See A_ScreenWidth
CoordMode can set coordinates mode to be relative to the whole screen. See CoordMode
MouseGetPos gets the current mouse coordinates. See MouseGetPos
Please take the time to analyse this example.
Example script
#If MouseIsTouchScreenRight()
WheelDown::^!e
#If
MouseIsTouchScreenRight() {
CoordMode, Mouse, Screen ;set coordinates mode to be relative to the whole screen
MouseGetPos, mX ;store the X coordinate of the mouse in `mX`
if ( abs(A_ScreenWidth-mX) <= 2 ) ;if the "absolute" difference is within 2 pixels
return true
return false
}

Actionscript 3.0 - MovieClip using it's own x, y coordinates

Basically, my problem is that I spawn a movieclip at coordinates where the mouse is clicked, then the movieclip is set to fall to a certain point, which is about to y=400.
The problem is that it takes the point where it spawned as the 0,0 coordinate and does it's actions using it. For an example, if I'd click at coordinates of 250y, it would fall to 650y. Is there a method where I can take the stage coordinates and use them in the movieclip, locally?
Also, I have another problem, which I haven't gotten around at fixing yet. My movieclips are set to highlight when they're hovered over with the mouse, but they are moving to the right at a constant speed. The problem is that the place where I have to hover over to highlight the movieclip doesn't change.
You would be interested in globalToLocal and localToGlobal methods on display object.
where globalToLocal(point) would transform the point to local coordinates. In your case the point is the stage x and stage y of the mouse event.

Camera movement using WASD on x/z plane only

I've been wearing my enter key down on google searches - I have a camera script based on the MouseOrbit.js asset. That's all working fine, but in addition to the basic orbiting and the zooming that I've added, I would like to use the WASD keys to move the camera around the world.
The W key would move the camera straight forward, however it would ignore the y axis. For example, using
transform.Translate(Vector3.Forward*Time.Delta*20);
moves the camera forward relative to the camera. This results in you quickly hitting the ground. Moving back oibviously does the opposite. The desired effect is sliding across the world without getting any closer/farther to it, regardless of the angle the camera is at.
The closest I can get is using the Space.World parameter of Translate(), but this does not take into account the rotation of my camera. I think if I could take that into account, this would be solved but I'm not clear on how to do that.
Thanks,
Chris
(From Tetrad on http://Gamedev.stackecxchange.com)
You don't need to use transform.Translate. Just calculate how much the camera should move forward for a given frame (something like if the W key is held down do deltaPos = transform.forward * Time.deltaTime * 20), set the Y value of that Vector3 to zero, then add that delta vector to the original position by adding it to the current position transform.position += deltaPos;

Mouse position not consistent with HTML canvas ondrag

I am trying to drag some shapes in HTML canvas but I am encountering a problem with respect to determining the change in mouse coordinates [dx,dy]
First of all, there is no problem in the coordinates themselves, stored in mousePos as the rollover effects work flawlessly. What I am doing is, upon first entering the shape, saving the mouse coordinates.
pos = {x : mousePos[0] , y : mousePos[1]};
Then, onMotion updates the coordinates everytime the mouse moves as well as recording the current position
dx=mousePos[0]-pos.x;
dy=mousePos[1]-pos.y;
pos = {x : mousePos[0] , y : mousePos[1]};
Then I add the dx and dy values to the shapes coordinates (lets take a simple rectangle as an example)
ctx.fillRect(0+this.dx,0+this.dy,100+this.dx,100+this.dy);
as long as the mouse doesn't move too fast, it works relatively well (not perfect though). If I move the mouse very quickly, without going out of the window, the rectangle does not catch up with the mouse. I can understand if there is a delay catching up to the mouse, but how can the delta values be off? Clearly we know where we started, and even if dozens/hundreds of pixels are skipped in the process, eventually the mouse should stop and the correct delta values should be calculated.
Any help would be greatly appreciated as I have hit a conceptual wall here.
You might try to get e.layerX-Y when the onMotion is fired to get the real position instead of the delta. This way it can't be "off".
To use this, place your shape into a div with style="padding:0px;margin=0px;" , because the position is relative to the parent block.