Using Arrow Keys as Inputs in C++ for Beginners

  • Context: C/C++ 
  • Thread starter Thread starter 99alastair
  • Start date Start date
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
5 replies · 9K views
99alastair
Messages
3
Reaction score
0
Arrow Key inputs - HELP!

hi. I'm 14 years old and have been programming for a year now. I have now however,come to a point where i need help. I'm using visual studios if that helps. I also program in C++. I have been needing to find out how to use the arrow keys as an input. For instance...When you press the left arrow button, a picture pox moves left etc. Thanks for any help. Alastair
 
Physics news on Phys.org
wow 14? ...search for ASCII values/chart (128 or 256 values)
They should have the arrow key values in them (though it may depend on the type of you keyboard you have).what are you using as your graphics display? .net/mfc?
 
yep, Only 14. I think the graphics is .net but not sure...how do you tell? do you know the code for the arrow key inputs? Thanks. Alastair
 
Last edited:
You don't say what language you are using in visual studio.

If it is VB then this is simple.
Set KeyPreview property of the form to true.
The arrow keystokes will be available in the forms KeyDown or KeyUp function. The only key not available is TAB key.

If C++ then I think this can be done with the Classwizzard.
I never wrote a GUI in C. Just .dlls and UNIX command line code, so I'm not sure.
Worst case here is to set up an event callback with some calls to kernal32.
Try looking in the samples directory.
 
Thanks mate. Normally, i program in C++ but i do know a small bit of VB too.
 
i think anytime you use form its .net and if you use winapp/document/doctemplate/view/framewnd its MFC.

for arrows keys...you can write a simple program to receive character inputs(cin/scanf) and then output the character as hex(%h or x?) or decimal(%d)

it depends on how you are receiving your inputs...and as notime said u can probably access by using classwizard...i'm pretty sure the GUI command is OnKeyChar. or OnKeyPress/Release in MSVC.

search in the environment help...but you may still have to find the ascii or keyboard number.

u can try this
http://www.jguru.com/faq/view.jsp?EID=475275