Log in

View Full Version : Click Mouse when I press on Keyboard?



joedeagan
11-10-2012, 07:38 PM
Hi, I just want to create a simple script, where if I press down on a keyboard key, lets say if I press down "Q", it would then, left click on the mouse 5x.

This is very simple, but I don't know the functions to do it.

Thanks.

riwu
11-11-2012, 01:45 AM
if IsKeyDown(VK_Q) then
for i:=1 to 5 do
ClickMouse2(mouse_Left);

May want to use a loop.

Lalaji
11-11-2012, 02:16 AM
Also, may want to add a wait between the clicks to avoid detection. and some randomness to each click.

joedeagan
11-11-2012, 06:42 PM
Thank you both of you for the tips, I have Scar Divi 3.36. I have an error that says Unknown identifier "IsKeyDown'

This is exactly what is in script box:

program New;
begin
if IsKeyDown(VK_Q) then
for i:=1 to 5 do
ClickMouse2(mouse_Left);
wait(500)
end.

Do I have to download some updates? I don't see any option to download any updates though. Thanks.

joedeagan
11-11-2012, 07:11 PM
Well, nevermind, I got the code to start working! I downloaded simba instead of Scar...

thank you guys.

My script:


program new;
{$DEFINE SMART}
{$I SRL/SRL.Simba}
{$i sps/sps.simba}
var
i: Integer;
procedure key;
begin
if IsKeyDown(VK_Q) then
for i:=1 to 5 do
ClickMouse2(mouse_Left);
wait(10)
end;
begin
repeat
key;
until(false)
end.

Kasi
11-11-2012, 07:13 PM
Thank you both of you for the tips, I have Scar Divi 3.36. I have an error that says Unknown identifier "IsKeyDown'

This is exactly what is in script box:


Do I have to download some updates? I don't see any option to download any updates though. Thanks.

that wont work, you'll need to wrap anything more then one line in a begin / end to make it repeat with the for loop


program new;
{$DEFINE SMART}
{$I SRL/SRL.Simba}
{$i sps/sps.simba}

var
i: Integer;

procedure key;
begin
if IsKeyDown(VK_Q) then
for i:=1 to 5 do
begin // this
ClickMouse2(mouse_Left);
wait(10)
end; // this
end;

begin
repeat
key;
until(false)
end.


also standardize your stuff.

Footy
11-11-2012, 07:13 PM
In the future, please follow SRL standards with your scripts, they make them much easietr to read and review. With that For..To..Do loop, you are clicking the mouse 5 times repeatedly with 0 time inbetween, is that what you were trying to do? or did you want a wait between the clicks? If so, you need to add a begin after the for..to..do, then put everything you want to happen, then an end. Just like braces in Java.

joedeagan
11-11-2012, 08:04 PM
Thank you Kasi and Footy. I want it to left mouse click as fast as possible, for only 5 times. So I changed it to ClickMouse because that was faster but it clicked like 15 times instead of 5 times. This is not for Runescape so I don't really need randomness or wait time. My thing is easy to read but when I copied and pasted, it looked weird, sorry about that.

Here is my code:



program new;
{$DEFINE SMART}
{$I SRL/SRL.Simba}
{$i sps/sps.simba}

var
i: Integer;
var x, y: integer;

procedure key;
begin
if IsKeyDown(VK_Q) then
for i:=1 to 5 do
begin // this
ClickMouse(x, y, mouse_Left);
end; // this
end;

begin
repeat
key;
until(false)
end.


Thanks.

Rezozo
11-11-2012, 08:21 PM
You sure you want that to be your script entirely? What I mean is right now, it set x, y, to 0,0 So...yea.
Plus, if that is all your script is going to do, Wont it be easier to put it like this:

program new;
{$DEFINE SMART}
{$I SRL/SRL.Simba}
{$i sps/sps.simba}

var
i: Integer;
var x, y: integer;

begin
x:=; {Choose an x coordinate}
y:=; {Choose a y coordinate}
repeat
if IsKeyDown(VK_Q) then
for i:=1 to 5 do
begin
ClickMouse(x, y, mouse_Left);
Wait(random(50));
end;
until(IsKeyDown(VK_E)); {Just to stop the script when you press E.}
end.

IDK, this is the first thing that came to mind :p I don't script that often, but I do love pascal.
~Rez

joedeagan
11-11-2012, 10:49 PM
You sure you want that to be your script entirely? What I mean is right now, it set x, y, to 0,0 So...yea.
Plus, if that is all your script is going to do, Wont it be easier to put it like this:

program new;
{$DEFINE SMART}
{$I SRL/SRL.Simba}
{$i sps/sps.simba}

var
i: Integer;
var x, y: integer;

begin
x:=; {Choose an x coordinate}
y:=; {Choose a y coordinate}
repeat
if IsKeyDown(VK_Q) then
for i:=1 to 5 do
begin
ClickMouse(x, y, mouse_Left);
Wait(random(50));
end;
until(IsKeyDown(VK_E)); {Just to stop the script when you press E.}
end.

IDK, this is the first thing that came to mind :p I don't script that often, but I do love pascal.
~Rez

Thank you! This worked perfectly.

I am working on my next challenge, just modifying the script to do other things like pressing keyboard buttons.

How come it would press the 'enter key' or the 'control key', but not letter keys like 'a' or 'z' or 's'? That is strange....

I am modifying the part where it says:


begin
ClickMouse(x, y, mouse_Left);
Wait(random(50));
end;

to:


KeyDown(17);
wait(RandomRange(50, 100));
KeyDown(41);


Can anyone tell me why it won't press the letter A but it will press the control key?

Thanks.

EDIT:
I just solved my own problem,



PressKey(VK_B);
wait(RandomRange(50, 100));
PressKey(VK_B);


On to the next challenge now. Thank you.

joedeagan
11-11-2012, 10:51 PM
I gave everyone who replied in this thread a reputation. Thank you guys...

joedeagan
11-12-2012, 12:27 AM
Hi, the script below was working perfectly, all of a sudden it won't repeat the loop?? It just says Compiled successfully in 671 ms. Successfully executed.

I don't want it to stop, it want it to just keep on looping. What is going on? It worked so well... what happened? Thanks.

program new;
{$DEFINE SMART}
{$I SRL/SRL.Simba}
{$i sps/sps.simba}

var
i: Integer;
var x, y: integer;

begin

repeat

{Left Mouse click 5x}
if IsKeyDown(VK_q) then
for i:=1 to 5 do
begin
ClickMouse(x, y, mouse_Left);
Wait(random(50));
end;
until(IsKeyDown(VK_E)); {Just to stop the script when you press E.}
end.

Footy
11-12-2012, 12:29 AM
The script is set up to keep looping until E is pressed, If you want it to loop forever, change that until(iskeydown(VK_E); to
until(false);

Lalaji
11-12-2012, 12:31 AM
program new;
{$DEFINE SMART}
{$I SRL/SRL.Simba}
{$i sps/sps.simba} //why do you need SPS include?

var
i: Integer;
var x, y: integer;

begin
repeat
for loop...
until(false);// it will keep looping forever.
end.

Edit: Footy beat me to it. :0

joedeagan
11-12-2012, 12:35 AM
Well, thank you guys for the help. I had to reboot the computer and it is working properly again, I was freaking out for a second... I don't know what happened before that... lol

It is working properly again... Here is what the note on the bottom said:


ERROR in TMThread.LoadFile
Exception in Script: Unable to find file 'C:\Simba\Includes\SRL/SRL/core/bank.simba' used from 'C:\Simba\Includes\SRL/SRL.Simba'
ERROR in TMThread.LoadFile
Exception in Script: Unable to find file 'C:\Simba\Includes\sps/sps.simba' used from 'C:\Users\Khiem\Desktop\key.simba'
[Hint] C:\Simba\Includes\SRL/SRL/core/globals.simba(55:3): Variable 'WORLDSWITCHERENABLED' never used at line 54
Compiled successfully in 546 ms.
Successfully executed.
[Hint] C:\Simba\Includes\SRL/SRL/core/globals.simba(55:3): Variable 'WORLDSWITCHERENABLED' never used at line 54
Compiled successfully in 562 ms.
Successfully executed.
[Hint] C:\Simba\Includes\SRL/SRL/core/globals.simba(55:3): Variable 'WORLDSWITCHERENABLED' never used at line 54
Compiled successfully in 593 ms.
Successfully executed.

joedeagan
11-12-2012, 12:37 AM
[simba]program new;
{$DEFINE SMART}
{$I SRL/SRL.Simba}
{$i sps/sps.simba} //why do you need SPS include?



hehe, lol, I included that because I was copying and pasting what others put in their scripts, I guess I will delete that now, Thanks! LOL

joedeagan
11-12-2012, 12:49 AM
I found out what I did that produced that problem that didn't loop.. for some reason, it quit looping when i add two comments one after the other... like this:


{Left Mouse click 5x}
{Press Q} <------Problem, don't add two comments one after the other like this.
if IsKeyDown(VK_q) then
for i:=1 to 5 do
begin
ClickMouse(x, y, mouse_Left);
Wait(random(50));
end;


I had to reboot yet again, never doing that anymore.

I can do this though:


{Left Mouse click 5x}
Press Q}
Of course everyone knows about this already, i think.

riwu
11-12-2012, 12:55 AM
I found out what I did that produced that problem that didn't loop.. for some reason, it quit looping when i add two comments one after the other... like this:


{Left Mouse click 5x}
{Press Q} <------Problem, don't add two comments one after the other like this.
if IsKeyDown(VK_q) then
for i:=1 to 5 do
begin
ClickMouse(x, y, mouse_Left);
Wait(random(50));
end;


I had to reboot yet again, never doing that anymore.

I can do this though:

Of course everyone knows about this already, i think.
Well I'm lost. What's wrong with it?

{Left Mouse click 5x}
{Press Q}
{insert whatever you like between this}
if IsKeyDown(VK_q) then
begin
GetMousePos(x, y);
for i:=1 to 5 do
ClickMouse(x, y, mouse_Left);
end;

joedeagan
11-12-2012, 01:03 AM
Well I'm lost. What's wrong with it?

{Left Mouse click 5x}
{Press Q}
{insert whatever you like between this}
if IsKeyDown(VK_q) then
begin
GetMousePos(x, y);
for i:=1 to 5 do
ClickMouse(x, y, mouse_Left);
end;


I really don't know what's wrong with it, I tried:


{Left Mouse click 5x
Press Q}
I got the same problem. I don't know what the hell is wrong with it. It won't loop, it would just say Successful compiled and stop the script. I have to reboot the computer, delete those things and it would work again...
I don't want it to stop. lol...
Now I just put it all in one line:


{Left Mouse click 5x, Press q}
No more problem, this is weird!

Rezozo
11-12-2012, 01:16 AM
Simba is trolling...
Glad my thing worked though, thanks for the +Rep :)
~Rez