JohnOne Posted September 14, 2014 Share Posted September 14, 2014 (edited) I remember when I first came to AutoIt and looking at them youtube video tutorials by someone or other and was moving the mouse with keyboard. Anyway, I don't know what possessed me but I decided to write one myself, I doubt it's the same as what I seen a few years ago. It's quite basic, and for beginners to look at and figure out what's going on beyond my meagre comments. It simply moves the mouse with arrow keys, and speeds the move up after a delay. Esc to Exit. expandcollapse popup#include <misc.au3> ; Set hotkeys to same func HotKeySet("{LEFT}", "_Move") HotKeySet("{RIGHT}", "_Move") HotKeySet("{UP}", "_Move") HotKeySet("{DOWN}", "_Move") HotKeySet("{Esc}", "_Move") ; Fine Tuning Global Const $MASTER_SPEED = 5 Global Const $DELAY = 300 Global Const $STEP = 5 Global Const $BEHAVIOUR = 0 ; 0 or 1 While 3 Sleep(333) WEnd Func _Move() ; Store hotkey Local $HKP = @HotKeyPressed ; For _IsPressed Local $KeyCode ; Unset hotkey Switch $HKP Case "{DOWN}" HotKeySet("{DOWN}") $KeyCode = "28" Case "{UP}" HotKeySet("{UP}") $KeyCode = "26" Case "{LEFT}" HotKeySet("{LEFT}") $KeyCode = "25" Case "{RIGHT}" HotKeySet("{RIGHT}") $KeyCode = "27" Case "{Esc}" Exit EndSwitch ; Sort some variables Local $SPEED = $MASTER_SPEED Local $hDll = DllOpen('user32.dll') Local $aPOS = MouseGetPos() Local $Timer = TimerInit() ; While the passed hotkey is down While _IsPressed($KeyCode, $hDll) If TimerDiff($Timer) > $DELAY And $SPEED > 1 Then $Timer = TimerInit() If $SPEED > 1 Then $SPEED -= 1 EndIf EndIf ; Test keycode Switch $KeyCode Case "28" $aPOS[1] += $STEP If $aPOS[1] >= @DesktopHeight Then If Not $BEHAVIOUR Then ExitLoop EndIf MouseMove($aPOS[0], 0, 0) $aPOS = MouseGetPos() EndIf Case "26" $aPOS[1] -= $STEP If $aPOS[1] <= 0 Then If Not $BEHAVIOUR Then ExitLoop EndIf MouseMove($aPOS[0], @DesktopHeight, 0) $aPOS = MouseGetPos() EndIf Case "25" $aPOS[0] -= $STEP If $aPOS[0] <= 0 Then If Not $BEHAVIOUR Then ExitLoop EndIf MouseMove(@DesktopWidth, $aPOS[1], 0) $aPOS = MouseGetPos() EndIf Case "27" $aPOS[0] += $STEP If $aPOS[0] >= @DesktopWidth Then If Not $BEHAVIOUR Then ExitLoop EndIf MouseMove(0, $aPOS[1], 0) $aPOS = MouseGetPos() EndIf EndSwitch MouseMove($aPOS[0], $aPOS[1], $SPEED) WEnd ;Clean up DllClose($hDll) ; Reset hotkey Switch $HKP Case "{DOWN}" HotKeySet("{DOWN}", "_Move") Case "{UP}" HotKeySet("{UP}", "_Move") Case "{LEFT}" HotKeySet("{LEFT}", "_Move") Case "{RIGHT}" HotKeySet("{RIGHT}", "_Move") EndSwitch EndFunc ;==>_Move EDIT: Forgot to mention, I left a nice little bug in the code, which can occur when $BEHAVIOUR Const is set to 1. Edited September 14, 2014 by JohnOne Danyfirex 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Exit Posted September 14, 2014 Share Posted September 14, 2014 And here an out of the box solution: http://windows.microsoft.com/en-us/windows7/use-mouse-keys-to-move-the-mouse-pointer App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
JohnOne Posted September 14, 2014 Author Share Posted September 14, 2014 That just made my mouse the size of a bus. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Gianni Posted September 14, 2014 Share Posted September 14, 2014 (edited) funny p.s. I had to change this code ; Reset hotkey Switch $HKP Case "{DOWN}" HotKeySet("{DOWN}", "DOWN") Case "{UP}" HotKeySet("{UP}", "UP") Case "{LEFT}" HotKeySet("{LEFT}", "LEFT") Case "{RIGHT}" HotKeySet("{RIGHT}", "RIGHT") EndSwitch with this ; Reset hotkey Switch $HKP Case "{DOWN}" HotKeySet("{DOWN}", "_Move") Case "{UP}" HotKeySet("{UP}", "_Move") Case "{LEFT}" HotKeySet("{LEFT}", "_Move") Case "{RIGHT}" HotKeySet("{RIGHT}", "_Move") EndSwitch p.p.s. maybe disabling the movement of the "text" cursor while moving the mouse cursor could be an improvement Edited September 14, 2014 by Chimp Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
JohnOne Posted September 14, 2014 Author Share Posted September 14, 2014 Good spot, I have a different func for the keys first. Thanks AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now