Jump to content

Recommended Posts

Posted (edited)

So I learned the basics of this program and I tried to make a program that moves the mouse with the arrow keys 1 pixel at a time, but I seem to be having some issues, here's what I got:

#include <AutoItConstants.au3>


Global $a = 0
Global $b = 0
Global $c = 0
Global $d = 0
Global $e = 1

func Start()

   EndFunc
HotKeySet("{F5}", "Start")

func Terminate()
   Exit
   EndFunc
HotKeySet("{F6}", "Terminate")

func PixelUp()
$a = 1
   EndFunc
HotKeySet("{UP}", "PixelUp")

func PixelDown()

   EndFunc
HotKeySet("{DOWN}", "PixelDown")

func PixelLeft()

   EndFunc
HotKeySet("{LEFT}", "PixelLeft")

func PixelRight()

   EndFunc
HotKeySet("{RIGHT}", "PixelRight")

Global $a = 0
Global $b = 0
Global $c = 0
Global $d = 0
Global $e = 1

$MousePos = MouseGetPos()
$MousePos[0] ; Mouse X position
$MousePos[1] ; Mouse Y position

While 1
   If $a = 1 Then
    $UP1 = $MousePos[0] + $e
    $UP2 = $MousePos[1] + $e
    MouseMove( $MousePos[0], $MousePos[1], 0)
    EndIf
WEnd

I know it sucks but i would really like to know what was my problem and i don't seem to find an answer on other forums or videos

Edited by Melba23
Added code tags
Posted (edited)

Hello welcome to the AutoIT forum :)

 

First thing please use the code tool when you post some code ;) that make things easy for us.

 

Ok I checked your code.... It's a bit hard for me to work with that. You are using a complicate way to do what you want :sweating:

 

My advise is try to go to the more simple way possible. 

 

I whould say you to try detecting when you press UP key and DOWN LEFT RIGHT. And then when you press your wanted key move the mouseposition of one pixel in the direction you just pressed.

 

You can do that with this include and that command : 

 

#include <Misc.au3>
_IsPressed ( $sHexKey )

 

Hexadecimal code of each keys are listed in the helpfile in the _IsPressed topic.

 

Exemple: 

#include <AutoItConstants.au3>
#include <Misc.au3>

HotKeySet("{F6}", "Terminate")

While 1
   Sleep(10)
      If _IsPressed ( "26" ) Then ;If UP key is pressed then
         PixelUp ()
;~    ElseIf _IsPressed ("??") Then ;Else if "??" key is pressed then
;~       PixelDown ()
      EndIf
WEnd

Func Terminate()
   Exit
EndFunc

Func PixelUp()
   $MousePos = MouseGetPos () ;Get position of mouse
   $MousePos[1] -= $MousePos ;Removing 1 pixel to the Y coordinate to go up.
   MouseMove ( $MousePos[0],$MousePos[1]) ; Moving the mouse to the new coordinate
EndFunc

 

Edited by caramen

My video tutorials : ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote

Spoiler

 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Posted

ah, I made exactly what you're asking for a while back actually. here ya go

Global $Mpos_x
Global $Mpos_y

HotKeySet("{UP}", "upcoords")
HotKeySet("{DOWN}", "downcoords")
HotKeySet("{LEFT}", "leftcoords")
HotKeySet("{RIGHT}", "rightcoords")

While 1
    Sleep(10)
WEnd

Func getcoords()
    $Mpos = MouseGetPos()
    $Mpos_x = $Mpos[0]
    $Mpos_y = $Mpos[1]
EndFunc

Func upcoords()

    getcoords()
    MouseMove(($Mpos_x + 0) , ($Mpos_y - 20), 0)

EndFunc

Func downcoords()

    getcoords()
    MouseMove(($Mpos_x + 0) , ($Mpos_y + 20), 0)

EndFunc

Func leftcoords()

    getcoords()
    MouseMove(($Mpos_x - 20) , ($Mpos_y + 0), 0)

EndFunc

Func rightcoords()

    getcoords()
    MouseMove(($Mpos_x + 20) , ($Mpos_y + 0), 0)

EndFunc

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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