Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

This discussion could help.
 
Share this answer
 
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
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
 
Share this answer
 
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. :)

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900