Using Arrow Keys as Inputs in C++: A Guide for Beginners

  • Thread starter 99alastair
  • Start date
In summary: QID=329436&AID=544759&PID=4In summary, Alastair has been trying to find out how to use the arrow keys as an input. He uses VB and the KeyPreview property of a form to enable arrow key input. He also mentions that he knows a small amount of C++. If he is using .NET then he can access the arrow key input with a simple program. If he is using MFC, he can look in the environment help for OnKeyChar.
  • #1
99alastair
3
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
  • #2
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?
 
  • #3
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:
  • #4
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.
 
  • #5
Thanks mate. Normally, i program in C++ but i do know a small bit of VB too.
 
  • #6
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
 

1. How do I use arrow keys for navigation on a web page?

Arrow keys can be used for navigation on a web page by pressing the left, right, up, or down arrow keys on your keyboard. This will allow you to move between different elements on the page, such as links, buttons, and form fields.

2. Can arrow keys be used to scroll a web page?

Yes, arrow keys can be used to scroll a web page. Pressing the up or down arrow keys will scroll the page up or down respectively. You can also use the Page Up and Page Down keys for larger scrolling movements.

3. How do I prevent arrow key inputs from scrolling a web page?

To prevent arrow key inputs from scrolling a web page, you can use JavaScript to capture the key press event and prevent the default behavior. Alternatively, you can also use CSS to set the overflow property to hidden on the element that you do not want to be scrollable.

4. How can I use arrow keys for game controls?

Arrow keys can be used for game controls by capturing the key press event using JavaScript and then using that event to trigger specific actions in the game. You can also use libraries such as jQuery or game development frameworks like Phaser to handle arrow key inputs for games.

5. Are arrow keys supported on all devices?

Arrow keys are supported on most devices, including desktop computers, laptops, and some mobile devices. However, some devices, such as smartphones, do not have physical arrow keys and may require alternative navigation methods. It is always a good practice to provide alternative input methods for users who may not be able to use arrow keys.

Similar threads

  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
3
Views
256
  • Programming and Computer Science
Replies
11
Views
2K
  • Programming and Computer Science
Replies
0
Views
217
Replies
7
Views
4K
  • Programming and Computer Science
Replies
1
Views
762
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
1
Views
917
  • Programming and Computer Science
Replies
2
Views
1K
Back
Top