How do i code: If (Button/Key = Down)
Moderators: JRL, Dorian (MJT support)
How do i code: If (Button/Key = Down)
Basically...
I want to write a script so while i hold a mouse button / keyboard key down, every second it will make x = x + 1
In a more program/script type language i want to do,
Label>Start
If (LeftMouseButton = Down)
{
x = x+1
}
Wait>1.0
Goto>Start
Can anyone help me with the exact terms, im only really having trouble with the condition in the If statement.
Thanks,
Chris
I want to write a script so while i hold a mouse button / keyboard key down, every second it will make x = x + 1
In a more program/script type language i want to do,
Label>Start
If (LeftMouseButton = Down)
{
x = x+1
}
Wait>1.0
Goto>Start
Can anyone help me with the exact terms, im only really having trouble with the condition in the If statement.
Thanks,
Chris
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
With Macro Scheduler you can use OnEvent and KeyDown to detect when a key or mouse button is pressed, but there's no way to know if it is being held down - there is no onkeydown/onkeyup. To be honest Macro Scheduler is probably not the right tool for you here. Macro Scheduler is for automating other applications. If you want to detect when a key is held down you are probably better off using VB.NET or the like.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
How do i do this? If you just tell me how to do:mtettmar wrote:With Macro Scheduler you can use OnEvent and KeyDown to detect when a key or mouse button is pressed,
OnEvent LeftMouseDown , x=x+1
or
KeyDown LeftMouse , x=x+1
whichever is how you'd go about it.
forget about the repetitions, i can do that with Labels and Goto's
Could you tell me the exact code for it. Thanks.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
With Macro Scheduler in front of you press F1. The help file will appear. Search for OnEvent.
So you would do this:
But, as I said, this doesn't distinguish between the mouse only going down and also being "clicked" (down followed by up). And there is no corresponding KeyUp event. So it's not going to help you do something only when the mouse is down.
So you would do this:
Code: Select all
OnEvent>KEY_DOWN,VK1,0,LeftMouseDown
Label>mainloop
Wait>0.2
Goto>mainloop
SRT>LeftMouseDown
MessageModal>Left mouse button down
END>LeftMouseDown
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Hmm. thanks for helping but that didnt quite make sense to me...
ill make it even easier to explain, i want this directly translated into code
Label>Start
OnEvent>KEY_DOWN,VK1,0,LeftMouseDown
Type "Z"
Wait>0.2
Goto>Start
What this means is... The code will infinately loop, and WHEN it runs through the loop AND the left mouse is down, it will type a z.
ill make it even easier to explain, i want this directly translated into code
Label>Start
OnEvent>KEY_DOWN,VK1,0,LeftMouseDown
Type "Z"
Wait>0.2
Goto>Start
What this means is... The code will infinately loop, and WHEN it runs through the loop AND the left mouse is down, it will type a z.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Did you read the help topic? Did you try my script code? If you did you'd see how easy it is to make it do what you want:
This macro will start Notepad. Then every time you press the left mouse button the letter z will be typed into notepad.
Please read the OnEvent topic in the help file, then read the script, then try the script. If you still don't understand post questions here. But we can only help people who help themselves. We cannot just write your code for you. We are not RentACoderForNothing.com
Code: Select all
OnEvent>KEY_DOWN,VK1,0,LeftMouseDown
Run>Notepad
WaitWindowOpen>notepad*
Label>mainloop
Wait>0.02
Goto>mainloop
SRT>LeftMouseDown
SetFocus>Notepad*
Send>z
END>LeftMouseDown
Please read the OnEvent topic in the help file, then read the script, then try the script. If you still don't understand post questions here. But we can only help people who help themselves. We cannot just write your code for you. We are not RentACoderForNothing.com

Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Err, yes, read my previous replies - I already told you this. That's why I said this is probably not the solution you are looking for.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Yes, Macro Scheduler has no method of detecting when the mouse is down and then later released.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
By "L" key do you mean the letter "L" or are you still referring to the left mouse button?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?