Keyboard Accessible?

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
ZimZam
Newbie
Posts: 1
Joined: Thu Feb 22, 2007 1:13 am

Keyboard Accessible?

Post by ZimZam » Thu Feb 22, 2007 1:18 am

I have been attempting to create a macro which presses the W key, and then holds it down for 10 seconds, however, when I use Record the program fails to measure any keyboard strokes. Rather it only finds mouse movement.

I also tried writing my own program, and it still does not execute the keyboard commands, only the mouse.

My keyboard is a logitech!

Thanks! :?:

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

Post by Marcus Tettmar » Thu Feb 22, 2007 8:47 am

Do you want the W key to be HELD down, or SENT for 10 seconds. There is a difference. Using the standard Send command, the key is sent which means the key is pressed and released in one go. So if you want to HOLD the key down for 10 seconds you have to use more advanced code. Here are both methods.

To send it for 10 seconds:

Code: Select all

VBSTART
VBEND

//focus notepad - put a few lines in notepad and set cursor to first line
SetFocus>Notepad*

//Press Down Arrow for 10 seconds
VBEval>Timer,stTime
Let>StopTime=stTime+10
Label>send_loop
  Send>w
  VBEval>Timer,elapsed
  If>elapsed<StopTime,send_loop
To HOLD it down use the code described at:
http://www.mjtnet.com/forum/viewtopic.php?t=1991

As follows:

Code: Select all

VBSTART
VBEND

//Key codes at http://www.mjtnet.com/vkcodes.htm
Let>VK_W=87
Let>ExtendedKey=1
Let>KeyUp=2

//focus notepad - put a few lines in notepad and set cursor to first line
SetFocus>Notepad*

//Press W for 10 seconds
VBEval>Timer,stTime
Let>StopTime=stTime+10
Label>press_loop
  LibFunc>user32.dll,keybd_event,r,VK_W,0,0,0
  VBEval>Timer,elapsed
  If>elapsed<StopTime,press_loop

//Now release W
Let>FLAGS={%ExtendedKey% OR %KeyUp%}
LibFunc>user32.dll,keybd_event,r,VK_DOWN,0,%KeyUp%,0
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

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