Holding a key down?

Just starting out? Need help? Post your questions and find answers here.
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Holding a key down?

Post by Dude »

This code holds down the "A" key, but doesn't repeat it. I want it to show "aaaaaaaaaa" but it only types the initial first "a" and then no more, even though the key state is down.

Code: Select all

keybd_event_(#VK_A,0,0,0)
Sleep_(5000)
It works if I do it in a loop like below, but is that really necessary?

Code: Select all

timeout.q=ElapsedMilliseconds()+1000
Repeat
  keybd_event_(#VK_A,0,0,0)
  Sleep_(1)
Until ElapsedMilliseconds()>timeout
User avatar
Otrebor
Enthusiast
Enthusiast
Posts: 201
Joined: Mon Mar 17, 2014 1:42 pm
Location: São Paulo, Brasil
Contact:

Re: Holding a key down?

Post by Otrebor »

Hi
This code was very usefull for me:
http://www.purebasic.fr/english/viewtop ... yboardHook
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: Holding a key down?

Post by Fig »

You need to release the key, repetition doesn't work else.

Code: Select all

Procedure simulerTouche(a.i)
  keybd_event_(a,0,0,0) ;key down
  keybd_event_(a,0,#KEYEVENTF_KEYUP,0) ;key up
EndProcedure
simulerTouche(#VK_A)
simulerTouche(#VK_A)
simulerTouche(#VK_A)
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
Post Reply