mouse returning back to opposite side . Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jerryrig
Posts: 40
Joined: 01 May 2021, 23:31

mouse returning back to opposite side .

06 May 2021, 03:28

usually mouse will stop moving after screen border ..... using ahk
is it possible to move mouse to the opposite side ( if i move mouse horizontally that will pass the right edge and start again from left edge .... like series of line drawn one after another) https youtu.be /3BJU2drrtCM?t=165 Broken Link for safety .... left to right ...again from left to right as long as i move move mouse horizonatally
User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: mouse returning back to opposite side .  Topic is solved

06 May 2021, 06:07

Code: Select all

#Persistent
#SingleInstance Force
margin := 10, freq := 250
SetTimer, Check, -%freq%
Return
Check:
MouseGetPos, xpos
last := zone, zone := (xpos < margin) + 2 * (xpos > A_ScreenWidth - margin)
If !last && zone
 MouseMove, (3 - 2 * zone) * A_ScreenWidth, 0,, R
SetTimer, Check, -%freq%
Return
jerryrig
Posts: 40
Joined: 01 May 2021, 23:31

Re: mouse returning back to opposite side .

06 May 2021, 08:15

it worked when i move mose to left .....
will u help me to expand it to top bottom and right ..... :cry:
jerryrig
Posts: 40
Joined: 01 May 2021, 23:31

Re: mouse returning back to opposite side .

06 May 2021, 08:37

i failed to expand it to right top and to bottom eventhough i understood 70% of ur code
User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: mouse returning back to opposite side .

06 May 2021, 09:12

You can use the same approach to your coding that will expand the script beyond what you initially described. Define zones of the screen according to the xpos and now also the ypos, which you can obtain through the same MouseGetPos command. You can use simple conditional ("If") statements to define those zones, such as 1, 2, 3, 4, and 5 (left, top, right, bottom, and center, for example). The rest is fairly simple: if the zone is the top one, then move the mouse to the bottom; and so on. That is what the current script does for left and right.

The script identifies the last (previous) zone, because it requires the previous zone to be the center, which is actually zone=0 in this script. This prevents problems that would otherwise occur with unwanted and unexpected repetitive mouse moves. In other words, the mouse will be moved only if it is moved from the center to one of the edges. After the move, no further moves will occur until the center is reached again. The center is easily reached because all other zones are quite narrow, as defined by the margin.

Other zone scripts have already been posted on this forum. You could probably find them if you search the forum for "zone" or "zones". Here are a few to get you started.

https://www.autohotkey.com/boards/viewtopic.php?f=76&t=84220

https://www.autohotkey.com/boards/viewtopic.php?p=387247#p387247
jerryrig
Posts: 40
Joined: 01 May 2021, 23:31

Re: mouse returning back to opposite side .

06 May 2021, 11:06

thnk u mike do u have any youtube stuffs ........
User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: mouse returning back to opposite side .

06 May 2021, 11:20

Sorry I do not! Best wishes. :)
jerryrig
Posts: 40
Joined: 01 May 2021, 23:31

Re: mouse returning back to opposite side .

07 May 2021, 09:29

Code: Select all

CoordMode,Mouse,Screen
#Persistent
SetTimer, wtf, 10
return

wtf:
MouseGetPos x,y
if(x=0 )
MouseMove A_ScreenWidth,Y

0::ExitApp
i have much more simpler code ...... im not comparing with urs ...as a beginer in ahk ....... what is the difference between ur code and mine ..... i respect ur work .... :D
User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: mouse returning back to opposite side .

07 May 2021, 11:05

The difference is precisely the difference that you created when you wrote the script:

1. Shortened the frequency (faster cycling)

2. Decreased the margin

3. Eliminated any effect on approaching the right edge of the screen

Functionally speaking, if both scripts work and meet your needs, then there is no difference.
jerryrig
Posts: 40
Joined: 01 May 2021, 23:31

Re: mouse returning back to opposite side .

07 May 2021, 12:40

thanks for helping me to develop this code ....u gave me a spark...I burn the entire city ....
jerryrig
Posts: 40
Joined: 01 May 2021, 23:31

Re: mouse returning back to opposite side .

07 May 2021, 12:40

u have good ahk skills ....why don't u create youtube to help others
User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: mouse returning back to opposite side .

07 May 2021, 12:46

Thank you for the suggestion-- a good idea. I would not know where to start, especially considering that others have already created videos and written tutorials or even books on using AHK. I don't want to reproduce effective materials that others have already created.

That said, I will remark that many of the posts on this forum cover the same ground over and over, on a recurring basis, monthly if not weekly, so I believe that the AHK community would benefit from a "FAQ" kind of wiki (not forum board) that answers the questions that are frequently asked on a recurring basis. Perhaps I can help in setting up that sort of wiki. On the other hand, there are some sites like Jack Dunning's that already provide that sort of format and material. A new wiki would probably make an important contribution, because the community could contribute to it, and it would address many basic issues, such as how to detect key holds, use a GUI to prompt for complex input, save variables in an INI file, etc. The wiki would go beyond the AHK documentation.
jerryrig
Posts: 40
Joined: 01 May 2021, 23:31

Re: mouse returning back to opposite side .

07 May 2021, 13:05

that's also correct ...
one more question mike.
if I'm having 2 joys stick (USB GAME CONTROLLER)
how do I get which is joy 1 and which is joy stick 2


2. if I understood joy sticks number how do I send a key press on joystick 2 ...
User avatar
mikeyww
Posts: 26588
Joined: 09 Sep 2014, 18:38

Re: mouse returning back to opposite side .

07 May 2021, 13:59

Sorry I do not have a joystick, but there are lots of posts and examples about the joysticks and joystick buttons. Would also see the doc on this.

https://www.autohotkey.com/docs/KeyList.htm#Joystick
jerryrig
Posts: 40
Joined: 01 May 2021, 23:31

Re: mouse returning back to opposite side .

07 May 2021, 17:05

I'm having a single joystick...

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot] and 115 guests