CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jun 2012
    Posts
    15

    Scanning arrow keys from keyboard.

    I'm building this windows forms application in visual c++ 2010, where in i want to control my robot's movement(via COM port) through arrow keys. I'm pretty new to visual c++, i've managed to control it by click, but wasn't quite successful implementing the arrow keys. I did check out the msdn forums, but all it did was confuse me. I hope you guys could help me out.
    Thanks in advance.

  2. #2
    Join Date
    Jun 2010
    Location
    Germany
    Posts
    2,675

    Re: Scanning arrow keys from keyboard.

    As I envision your scenario, it's probably most adequate to handle the keystrokes at the form level by setting up a KeyDown event handler for your form. You'll find constants representing the arrow keys in the Keys enumeration. You may need to set the form's KeyPreview property to true to prevent controls that consume arrow keystrokes themselves (like a textbox) from intercepting the keystrokes before the form gets notice of them.

    However, as I understand your description, you already have implemented robot control by button clicks. In this case it may be niftier to simply dispatch the keystrokes to be handled as button clicks by using a class like the one from http://forums.codeguru.com/showthrea...ngle-menu-item. As posted, the class is designed to work with menu items, not buttons, but it should not be too complicated to modify it accordingly. (In fact, in a bunch of my real-life apps I'm using a version of that class that automatically does support both menu items and arbitrary controls, including buttons, and not even that modification was really spectacular. Otherwise the class is practically identical to the posted version.)
    I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.

    This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.

  3. #3
    Join Date
    Jun 2012
    Posts
    15

    Talking Re: Scanning arrow keys from keyboard.

    Thanks a million, Eri523. It worked like magic.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured