Jump to content

Check if mouse moved to left or right


Jack023
 Share

Recommended Posts

Hey all,

At the moment i'm learning autoit and i was wondering how i could see if my mouse move on the X to left or Right?

I use this to get the center of the screen.

$x = @DesktopWidth / 2
$y = @DesktopHeight / 2

Now i want, in a loop.

If mouse move to left side of the $x then 

else if mouse move to right side of the $x then

endif

Is this possible?

 

Link to comment
Share on other sites

Alright

now got this:

$x = @DesktopWidth / 2
$y = @DesktopHeight / 2
$i = 0
Do
    Local $pos = MouseGetPos()
    if $pos[0] <> $x then
    MouseMove($x, $y)
    $i += 1
    EndIf
Until $i = 10

It do this:

If mouse is not in center, move it to center.

This is just simple, but i want like this:

If mouse left or mouse is right of center?

apart from each other

Link to comment
Share on other sites

$pos[0] <  $x is to the left,$pos[0] >  $x is to the right. Wouldn't it have been easier to try this out for yourself rather than posting this, and then replying to yourself 35 minutes later?

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I know,

but still not fixed..

$x = @DesktopWidth / 2
$y = @DesktopHeight / 2
$i = 0
Do
    $x = @DesktopWidth / 2
    sleep(1000)
    Local $pos = MouseGetPos()
    if $pos[0] < $x then
        Do
            Send("{a down}")
        Until $pos[0] >$x


    ElseIf $pos[0] > $x Then
        While $pos[0] > $x
            Send("{d down}")
        WEnd
    $i += 1
    EndIf
Until $i = 10
Link to comment
Share on other sites

  • Developers

How does getting the mid screen point help determining wehther you are moving left or right?

You should save the last position and compare to that to determine which direction it moved.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

Well , i was trying it in a game of my friend to make my skills for autoit better. only it always aim on the center of the screen.

any fix for that?

Well, in that case start reading here before continuing your question.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...