How do i code: If (Button/Key = Down)

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Jozsa
Newbie
Posts: 10
Joined: Fri Apr 27, 2007 9:56 am

How do i code: If (Button/Key = Down)

Post by Jozsa » Fri Apr 27, 2007 10:02 am

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

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Apr 27, 2007 10:17 am

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?

Jozsa
Newbie
Posts: 10
Joined: Fri Apr 27, 2007 9:56 am

Post by Jozsa » Fri Apr 27, 2007 10:21 am

mtettmar wrote:With Macro Scheduler you can use OnEvent and KeyDown to detect when a key or mouse button is pressed,
How do i do this? If you just tell me how to do:

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.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Apr 27, 2007 10:27 am

With Macro Scheduler in front of you press F1. The help file will appear. Search for OnEvent.

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
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.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Jozsa
Newbie
Posts: 10
Joined: Fri Apr 27, 2007 9:56 am

Post by Jozsa » Fri Apr 27, 2007 10:33 am

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.

Jozsa
Newbie
Posts: 10
Joined: Fri Apr 27, 2007 9:56 am

Post by Jozsa » Fri Apr 27, 2007 10:38 am

Label>Start

OnEvent>KEY_DOWN,VK1,0,LeftMouseDown

SRT>LeftMouseDown
Press ALT
END>LeftMouseDown

Wait>0.2
Goto>Start





THANKS SON, i playd around, (Ill just replace the Press ALT line with Let x = x + 1)

you are my hero. works perfectly.

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Apr 27, 2007 10:40 am

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:

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
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 ;-)
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Jozsa
Newbie
Posts: 10
Joined: Fri Apr 27, 2007 9:56 am

Post by Jozsa » Fri Apr 27, 2007 10:46 am

haha, well thanks for all the help.
but i just ran into a problem...

theoretically...
if i hold down the mouse button, every time the loop runs, it will detect its down, and type a Z... it doesnt though. it will only type a z when i CLICK the mouse while its running

any idea how to do what i want?

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Apr 27, 2007 10:49 am

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?

Jozsa
Newbie
Posts: 10
Joined: Fri Apr 27, 2007 9:56 am

Post by Jozsa » Fri Apr 27, 2007 10:52 am

so its impossible to do what i want with a macro?

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Apr 27, 2007 10:56 am

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?

Jozsa
Newbie
Posts: 10
Joined: Fri Apr 27, 2007 9:56 am

Post by Jozsa » Fri Apr 27, 2007 10:56 am

Sure it does, i just got it to work perfectly :)

Thanks for all the help though :D!

And sorry for being a programmy newb.

Jozsa
Newbie
Posts: 10
Joined: Fri Apr 27, 2007 9:56 am

Post by Jozsa » Fri Apr 27, 2007 10:59 am

but just one REALLY basic question

how do i make macro scheduler do:

Push L Key in
wait 0.2
Release L Key
wait 0.2

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Apr 27, 2007 11:01 am

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?

Jozsa
Newbie
Posts: 10
Joined: Fri Apr 27, 2007 9:56 am

Post by Jozsa » Fri Apr 27, 2007 11:06 am

the letter, sorry for ambiguity

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts