Autohotkey - Remap mouse wheel when mouse touch edge of screen - autohotkey

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
}

Related

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

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

How to detect exact location of mouse click on sprite in scratch

I would like to detect the exact location of the mouse click within the 3x3 grid displayed on the screen. How can this be done in MIT scratch? Any suggestions?
There are two ways to do this.
You could create 9 sprites, hide, and use the When this sprite clicked event...
...but it would be a whole lot of unnecessary sprites.
Or you can do the following:
As #PullJosh said, you can use the mouse x and y blocks. Just do some math:
You know that the stage goes from X: -240 to 240, Y: -180 to 180.
Just put that into some code to detect ranges, below is a link to a project that is an example of this:
This project
(Note: This assumes the grid boxes are the same size.)
when greenFlag pressed
forever
if <mouse down?> then
set (lastMouseClickX) to (mouse x)
set (lastMouseClickY) to (mouse y)
end
wait until <not<mouse down?>>
end```
This is pretty simple if you want to involve 2 variables in this:
All you really need to do is to set the mousex position to a variable and the mousey position to a variable after the sprite detects a click on it. Here is an example:

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

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.

Dragging sprites in Scratch

How do I drag sprites during execution in Scratch?
This is covered on the Scratch Wiki.
boisvert's answer is technically correct, however, his script will always drag the sprite from it's center. Using a slightly more advanced script will drag from the spot it was picked up, more like the padlock:
when green flag clicked
forever
if <<mouse down?> and <touching [mouse-pointer v]?>>
repeat until <not <mouse down?>>
set [offset x v] to ((x position) - (mouse x))
set [offset y v] to ((y position) - (mouse y))
go to x: ((mouse x) + (offset x)) y: ((mouse y) + (offset y))
end
else
wait until <not <mouse down?>>
end
(The wiki link above has this is visual blocks format.)
Click the padlock next to the sprite name. It will look open; then the sprite becomes draggable in the executable version.
Alternatively, you could program its dragged behaviour with a script:
if <mouse down>
set x to (mouse x)
set y to (mouse y)
it can be made more clever, to follow the mouse at an offset position, with a delay, snap to a position when dropped, highlight something as it passes over it... If you use a script your choices are limitless.
For a quick and simple route, all you have to do is click the info button of the sprite: Click here for image 1.
After that you should find the box that says: can drag in player and click that: Click here for image 2.
This is actually it. Now whenever somebody plays your game they can drag the sprite. You just have to let them know that it is possible since most project don't allow it.
If you would not mind if the sprite is still draggable when the script is not running then you press the i button at the top-right corner when the sprite is selected. Then, you press Can drag in player. However, this does not work for Scratch 3.0 and so you would need to use my other method, scripting.
when green flag clicked
forever
if <<mouse down?> and <touching [mouse-pointer]>>
go to [mouse-pointer]
You can use the <mouse down?> boolean, the touching [mouse pointer]? and the variables(mouse x) and (mouse y) to get the mouse's coordinates and to detect if the mouse is down. Here is how you can do it:
when green flag clicked //when the green flag is clicked,
forever //do this forever,
if touching [mouse pointer]? AND mouse down? //touching the mouse pointer? The mouse down?
set x to (mouse x) //set my x position to the mouse's x position.
set y to (mouse y) //set my y position to the mouse's y position.
end if loop //if everything above is not true, don't go to mouse
end forever loop //repeat this process forever!
If you need more help with other things, you ca follow me if you want to #endermite334.
Sprites are by default draggable in Scratch 3.0. You can change that by using set drag mode [not draggable]