Jump to content

I need a script to Move my Mouse and Press things on my keyboard

Bop

I know. I know. This is probably stupid easy. But I'm a major noob and trying to get into coding, and I need to know how to do these things for a Project I'm working on. I have the first part of it finished but I need to know how to write a script to basically move my mouse click and type practically. This also dosen't have to fit into my original code, so I just need to know how to write this in a language like idk Python or whatever compile it and then I can just set it to run in my original script which will work just fine.

Link to comment
Share on other sites

Link to post
Share on other sites

Personally, I use Autohotkey for stuff like that.

Hand, n. A singular instrument worn at the end of the human arm and commonly thrust into somebody’s pocket.

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, WereCatf said:

Personally, I use Autohotkey for stuff like that.

I'm trying to do it all without existing programs. I wanna like push myself and not just rely on others work.

Link to comment
Share on other sites

Link to post
Share on other sites

I will look for a course that I did yeeaars ago, but there will be plenty of examples for this online and shouln't be to hard.

 

If you decide to give AHK a try you can basicly code your own macros there, why reinvent the wheel.

 

Edit: This should get you started: https://stackoverflow.com/questions/1181464/controlling-mouse-with-python

Link to comment
Share on other sites

Link to post
Share on other sites

10 hours ago, Bop said:

I'm trying to do it all without existing programs. I wanna like push myself and not just rely on others work.

Totally understandable while learning but just remember there is no need to reinvent the wheel. If there is a framework that fits your usecase you should definitely use it.  

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

you could go with Sikuli

It's basically a tool to script movements and actions on the computer. It also recognizes images so instead of using coordinates like you would have to do in AHK you can just use an image of what you want to act on.

The code you would have to write is basically a python code with a nice IDE so you can see what you are clicking on instead of just adding file images.

 

also, I'm just going to get you out of your error here:

12 hours ago, Bop said:

I'm trying to do it all without existing programs. I wanna like push myself and not just rely on others work.

Part of your learning process has to be to look at a piece of code and think "How can this be applied to what I want to do", more often than not, you will find that something completely unrelated can help you solve part of a problem and you will learn a lot that way.

Also if you want to get into coding don't go and look online for a piece of code that will solve your problem (which I know you didn't do) but don't refuse a tool when you have the opportunity. If no one used any tool developed by others we would never have gotten even to punch cards.

The best way to measure the quality of a piece of code is "Oh F*** "s per line

Link to comment
Share on other sites

Link to post
Share on other sites

Autohotkey is legit and the best answer.

pyauto is great if you like python, you'll be reinventing a reinvented wheel here, but that may be the best option if you like full control and want to understand every step.

 

If you're in a Windows Environment (not exclusively anymore!) I would also add PowerShell to the list. It's very powerful and I think having a good grasp of it, helps programmers of all skill levels gain full use and understanding of their machine. It's also the default Windows Shell going forward, so the more you can do with it the less existing programs you'll need.

Link to comment
Share on other sites

Link to post
Share on other sites

So the .NET framework already has a class built for sending keys. I have actually used this class before with a crude powershell script to type stuff stored in files character by character at a slow rate. 

 

Here is a bare bones way of doing that:

$myString = "wow"
Start-Sleep -s 2
[System.Windows.Forms.SendKeys]::SendWait($myString)

There is also a class for mouse stuff. The code bellow will move the mouse to 500, 500 (width length). 

[Windows.Forms.Cursor]::Position = "$(500),$(500)"

If you want to get fancy, you could even track the current location of the mouse and do something with it.

$X = [System.Windows.Forms.Cursor]::Position.X
$Y = [System.Windows.Forms.Cursor]::Position.Y
Write-Output "X: $X | Y: $Y"

 

Link to comment
Share on other sites

Link to post
Share on other sites

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

×