Jump to content
Macro Express Forums

Constrain to horizontal mouse movement only


Recommended Posts

Is there a way to script it so that when I hold a certain key, or hold down the middle mouse button, it makes the mouse can only move in horizontal directions - any vertical movement should be prohibited

If there is no way to hold a key, can it be make as a toggle on/off that restricts up/down mouse movement?

I found a way with AutoHotKey (here), but would much rather use MacroExpress as it is currently on the user's PC for other purposes already.

Thanks

 

Link to comment
Share on other sites

I don't know about holding a key -- can't think how that would be done.  But you might be able to toggle as follows; it is essentially the same solution as you came up with in AutoHotKey.  
1)    User starts Macro A with a keystroke (the toggle key).  
2)    Macro A runs Macro B and ends itself.
3)    Macro B records current mouse position (A,B) (vertical component B is all that counts).  Macro B then loops continuously (Repeat loop), with a very short delay in each iteration of the loop, a few milliseconds.  Each time through the loop it resets the vertical component of mouse position to whatever the starting position was.  That is, if current mouse position is found to be (x,y) the macro moves the mouse to (x,B).  So the user is able to move the mouse both horizontally and vertically, but the vertical movement is almost instantly cancelled by Macro B.      
4)    User again starts Macro A with a keystroke (the toggle key).  
5)    Macro A determines that Macro B is already running, and stops Macro B.  

Worth a try, fairly simple to code.  Don’t know what impact it will have on CPU usage due to the looping – probably OK.   On my PC the resulting mouse movement is kind of choppy, which may or may not be acceptable to you.  

Variable Set String %T1% "2"
Get Mouse Position Screen: %N1%, %N2%
Repeat Until %T1% = "1"
  Get Mouse Position Screen: %N1%, %N3%
  Mouse Move Screen %N1%, %N2%
  Delay 1 Milliseconds
Repeat End

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...