rapt
rapt

Reputation: 12230

Windows command script that moves mouse cursor N pixels?

I am trying to find out how to move the mouse cursor N pixels to some direction.... through a command script, since I cannot install anything on my computer.

I basically try to keep the screen active forever, until I kill the script.

(Yes, I've been searching high and low for a way to do it by a command script.... but could not find anything. I hope it's possible.)

Upvotes: 22

Views: 177112

Answers (6)

Mixailka
Mixailka

Reputation: 1

Here is the code with comments for the Batch file. If you have your own coordinates, then you can not specify them and, accordingly, do everything in one powershell line.

@echo off
rem Disable command output in the console

setlocal
rem Start local variable scope

set "x=138"
set "y=156"
rem Set the values of variables x and y for X and Y coordinates

powershell -Command "[Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms'); [System.Windows.Forms.Cursor]::Position = New-Object System.Drawing.Point(%x%, %y%)"
rem Run PowerShell to move the mouse cursor to the specified coordinates

endlocal
rem End local variable scope

Upvotes: 0

gawkface
gawkface

Reputation: 2312

I basically try to keep the screen active forever, until I kill the script.

I created following windows command console executable infinite loop (that can be manually exited with interrupt CTRL+C)

FOR /L %%X IN (0,0,1) DO @(
    timeout 30
    start cmd.exe /k "exit"
)

I now have it handy in a batch script to execute at will

Notes

  1. timeout N is every N seconds - ofcourse it can be any number smaller than windows sleep timeout set
  2. See this section for the for loop syntax using iteration step counter where (0,0,1) is (start,step,end) so the step being 0, never reaches the end 1
  3. I played around with a variation where you can launch the new console (right now its just exiting but instead could have been start cmd.exe /k "timeout 2 & exit") to also have a nested timeout. One can use that to be aware there is a background script running (to remember to close it, though this nested popup can come in the way when focussing on windows when resuming work)
  4. cmd.exe /k
  5. start

Upvotes: 1

Stephen
Stephen

Reputation: 37

try setting sleep mode to 'none', but if you want to move your mouse without even touching it, download memz clean and let the "random cursor movement" to be bluish. now enjoy. (if it doesn't work, the payloads must be disabled. try doing shift+esc to enable/disable payloads. try doing ctrl+shift+s to skip some time because in some minutes the mouse will shake more better.)

Upvotes: 1

SharpNip
SharpNip

Reputation: 360

(Late answer but can still be useful for others) If you just want to keep your computer from falling asleep, the software "Caffeine" does this quite well.

Upvotes: 6

npocmaka
npocmaka

Reputation: 57262

The most straightforward way to manipulate mouse with batch file is with

rundll32 user32.dll,SetCursorPos

But this is not very useful - just sets the mouse to 0,0 position.

Check the mouse.bat - it is a self compiled C#/batch file and does not require external tools and the source is visible and editable.

Examples:

//clicks at the current position
call mouse click

//double clicks at the current position
call mouse doubleClick

//right clicks at the current position
call mouse rightClick

//returns the position of the cursor
call mouse position

//scrolls up the mouse wheel with 1500 units
call mouse scrollUp 150

//scrolls down with 100 postitions
call mouse scrollDown 100

 //relatively(from the current position) moves the mouse with 100 horizontal and 100 vertial postitions
call mouse moveBy 100x100

//absolute positioning
call mouse moveTo 100x100

//relative drag (lefclick and move)
call mouse dragBy 300x200

//absolute drag
call mouse dragTo 500x500

Upvotes: 27

MoE
MoE

Reputation: 171

Search for NirCmd, and install it in C:\windows, and do:

nircmd setcursor 100 50
nircmd movecursor 10 10

or another commands for clicks etc.

Upvotes: 17

Related Questions