Using Arrow Keys as Inputs in C++ for Beginners

  • Context: C/C++ 
  • Thread starter Thread starter 99alastair
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around how to use arrow keys as input in C++ programming, specifically within the context of Visual Studio. Participants explore various methods and considerations for capturing these inputs in a graphical application.

Discussion Character

  • Exploratory
  • Technical explanation
  • Homework-related

Main Points Raised

  • One participant, Alastair, seeks assistance with using arrow keys to move a picture box in a C++ program.
  • Another participant suggests looking up ASCII values for arrow keys, noting that the values may depend on the keyboard type.
  • There is a discussion about determining whether the graphics framework being used is .NET or MFC, with one participant indicating that .NET is likely if forms are being used.
  • A suggestion is made that if using Visual Basic, the KeyPreview property can be set to true to capture arrow key events easily.
  • For C++, one participant mentions the possibility of using ClassWizard and event callbacks, although they express uncertainty about GUI programming in C++.
  • Another participant proposes writing a simple program to receive character inputs and output them in hexadecimal or decimal format, emphasizing the importance of understanding how inputs are received.
  • A link to additional resources is provided for further exploration of the topic.

Areas of Agreement / Disagreement

Participants express varying levels of certainty regarding the methods to capture arrow key inputs, with no consensus reached on a specific solution or approach. Multiple perspectives on the programming environment and methods remain present.

Contextual Notes

Participants do not clarify the specific programming environment or framework being used, leading to potential ambiguity in the solutions proposed. There is also uncertainty regarding the exact method to capture arrow key inputs in C++.

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
 
Technology 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
 

Similar threads

  • · Replies 0 ·
Replies
0
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 25 ·
Replies
25
Views
1K
Replies
4
Views
4K
  • · Replies 14 ·
Replies
14
Views
35K