Click here to Skip to main content
14,331,362 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am developing a game for which i wanted to press and hold up or down or left or right key for some time the game is racing.

Normally we send keys through sendkey functions but for holding a particular value i don't know how to do it.
Posted
Updated 28-Apr-11 0:02am
Rate this:
Please Sign up or sign in to vote.

Solution 1

This discussion could help.
   
Comments
Sergey Alexandrovich Kryukov 28-Apr-11 10:33am
   
It should works but the references show the obsolete method; it was superseded by SendInput. My 5.
Please see my answer.
--SA
Nish Nishant 28-Apr-11 10:51am
   
>> My 5. <<

His post has a single 4. So you changed your mind? :-)
Abhinav S 28-Apr-11 11:08am
   
Yes. :)
Nish Nishant 28-Apr-11 11:09am
   
I gave you a 5 (a real 5, not an SA-5 which is usually a 4) *grin*
Sergey Alexandrovich Kryukov 28-Apr-11 11:37am
   
I actually vote more 5s then 4s but I think in many cases my 5 was too much.
In this case I meant to vote 4 by the minor reason I explained (obsolete function) and I did that, but by mistake I typed "5" in text. As I was my mistake, I fixed it by re-voting 5 :-)
--SA
Nish Nishant 28-Apr-11 11:38am
   
I was just kidding, SA! :-)
Sergey Alexandrovich Kryukov 28-Apr-11 12:32pm
   
:-)
Nevertheless I don't want to make accidental mistakes here (well, conceptual mistakes are unavoidable), so I suggest not to hesitate to point out any mistakes in comments -- accidents happen; for example, my son recently hit our car into another one; :< and I cannot do anything except down-voting him :-)
--SA
Nish Nishant 28-Apr-11 12:33pm
   
Heh :-)

Good thing for me, my son's 3. Not old enough to wreck cars :-)
Sergey Alexandrovich Kryukov 28-Apr-11 12:39pm
   
Don't worry: the car-hitting skills will come soon. Take care of smaller items and animals for now.
--SA
Abhinav S 28-Apr-11 13:24pm
   
Ha ha :)
Abhinav S 28-Apr-11 11:08am
   
5? or 4? :)
Nish Nishant 28-Apr-11 11:35am
   
Fixed now :-)
Sergey Alexandrovich Kryukov 28-Apr-11 11:37am
   
I re-voted; motivated above.
--SA
Abhinav S 28-Apr-11 13:25pm
   
I noticed. :)
Thanks.
Rate this:
Please Sign up or sign in to vote.

Solution 3

Yes, SendKey is very limited.

First of all, think why would you need to simulate a key input. Normal UI development never requires it. This is only used for creation of some system tricks, suck as playing back keyboard macro or Virtual Keyboard.

The comprehensive way of simulation input is using Windows API SendInput through P/Invoke.
See http://msdn.microsoft.com/en-us/library/ms646310(v=vs.85).aspx[^].

—SA
   
Comments
Nish Nishant 28-Apr-11 10:52am
   
Voted 5 (actually a 5, and not a 4 as some people do) ;-)
Sergey Alexandrovich Kryukov 28-Apr-11 11:33am
   
Thank you, Nishant.
Do you mean my votes? I guess just comes in fashion :-)
At least when I vote 4 it means I feel enough respect to an expert to explain why not 5 :-)
--SA
Nish Nishant 28-Apr-11 11:35am
   
I meant your vote of 4 above to Abhinav but your comment was 5 :-) (btw I was just kidding you). And seems you have fixed that now.
Sergey Alexandrovich Kryukov 28-Apr-11 12:33pm
   
Yep. Discussed. See my previous comment.
Thank you, Nishant.
--SA
Abhinav S 28-Apr-11 13:27pm
   
My 5 for this answer and correcting my vote. :)
Sergey Alexandrovich Kryukov 28-Apr-11 13:46pm
   
Thank you, Abhinav. I hope your vote is not depending to mine in any way... :-)
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100