keydown question

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
idiot
Macro Veteran
Posts: 152
Joined: Thu Mar 01, 2007 9:21 am

keydown question

Post by idiot » Sun Nov 03, 2013 12:23 am

was trying to find a way to where if i press a key it holds that key down and when i press that key again it releases it

im totally at a loss of how i could do this please helps thanks love ya

this is what i was thinking is it right?

Code: Select all


wait>5



GetActiveWindow>window_title,x,y
setfocus>%window_title%
label>start
WaitKeyDown>q
wait>1
Let>VK_q=81
Let>ExtendedKey=1
Let>KeyUp=2

LibFunc>user32.dll,keybd_event,r,VK_q,0,ExtendedKey,0

WaitKeyDown>q
Let>VK_q=81
Let>ExtendedKey=1
Let>KeyUp=2

Let>FLAGS={%ExtendedKey% OR %KeyUp%}
LibFunc>user32.dll,keybd_event,r,VK_q,0,FLAGS,0

goto>start

if idiots rule the world then im the king!!!!
i want a free t-shirt give me all of your rep!!!
please give me pro version of macro scheduler and appnavigator!!!

User avatar
Meryl
Staff
Posts: 124
Joined: Wed Sep 19, 2012 1:53 pm
Location: Texas
Contact:

Post by Meryl » Mon Nov 04, 2013 11:17 pm

No brilliant ideas from our brilliant minds?

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

Post by Marcus Tettmar » Tue Nov 05, 2013 7:38 am

I can't really see how that works because the second waitkeydown is surely going to fire immediately because prior to that the script holds it down, so it is already down.

To be honest I can't imagine there is any way to do this. I think you'd need a different key to signify when the first one should be 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?

idiot
Macro Veteran
Posts: 152
Joined: Thu Mar 01, 2007 9:21 am

Post by idiot » Tue Nov 05, 2013 8:21 am

what im trying to do is toggle a key have it downkey when button is pressed have it keyup when pressed again guess i will keep working on it usually i can figure some wierd way of how to do it this one kinda works but really want 1 key to do it i will try your suggestion of using a different toggle key to toggle a different button is there possibly a waitkey release function
:?: :?: :?: :?: cause if there was a waitkeyup then if i pressed it again it would release it and work
if idiots rule the world then im the king!!!!
i want a free t-shirt give me all of your rep!!!
please give me pro version of macro scheduler and appnavigator!!!

User avatar
JRL
Automation Wizard
Posts: 3524
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Nov 05, 2013 2:25 pm

What is happening while you hold the key down? Can you do that programmatically? If yes you could simply use a key_down OnEvent and have a toggling flag in the Event's subroutine.

User avatar
JRL
Automation Wizard
Posts: 3524
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Nov 05, 2013 9:39 pm

Will this work?

Code: Select all

//Start this script and press and hold the "a" key
//The mouse should move to 500,500 and stay there
//no matter where you try to move it.
//Release the "a" key and press it again and the
//mouse should move to 0,0 and stay there
//no matter where you try to move it.
OnEvent>key_down,a,0,Pressed
Let>kk=0
Let>CornerFlag=0

Label>Loop
  //If you remove this wait you will need to bump
  //up the number at teh end of If>kk>3
  //Perhaps up to If>kk>20
  Wait>0.01
  If>KK>0
    Add>kk,1
    If>kk>3
      Let>kk=0
      If>CornerFlag=0
        Let>CornerFlag=1
      Else
        Let>CornerFlag=0
      EndIF
    EndIf
  EndIf
Goto>Loop

SRT>Pressed
  If>CornerFlag=0
    Let>kk=1
    //What to do on first key toggle
    Mousemove>500,500
  Else
    Let>kk=1
    //What to do on second key toggle
    Mousemove>0,0
  EndIf
END>Pressed

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