locked
Event Handling when Arrow Keys is pressed.

    Question

  • hi

    I am a beginner. I am making a game in which i want  to move an object with the arrow key(left, right, up ,down) in my WINDOWS STORE APP.  I have put on screen keys  but for laptop and PC i also want to include the arrow key movement. Please help.


    Thursday, July 31, 2014 4:59 PM

Answers

  • Found the answer------ its VirtualKey.<some_keyon _Keyboard> private void Button_KeyDown(object sender, KeyRoutedEventArgs e) { if (e.Key == Windows.System.VirtualKey.Up) Storyboard1.Begin(); }
    • Marked as answer by -ManishAnand Thursday, July 31, 2014 5:47 PM
    Thursday, July 31, 2014 5:47 PM

All replies

  • You can use the KeyDown event to handle this event in your program. Using this, you can then use any condition to detect the key that was pressed by the user and change the Object's state in your game.

    http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keydown(v=vs.110).aspx

    if(e.KeyCode == Keys.Up) {
      // up key
    }
    
    // add more else statements..

    You can use this following StackOverflow post to learn more about it. 

    http://stackoverflow.com/a/5606692/1762944

    Good luck!


    ~!Firewall!~

    Thursday, July 31, 2014 5:04 PM
  • But in Windows store app it says that// "Keys" does not belongs to current context.//
    Thursday, July 31, 2014 5:38 PM
  • Found the answer------ its VirtualKey.<some_keyon _Keyboard> private void Button_KeyDown(object sender, KeyRoutedEventArgs e) { if (e.Key == Windows.System.VirtualKey.Up) Storyboard1.Begin(); }
    • Marked as answer by -ManishAnand Thursday, July 31, 2014 5:47 PM
    Thursday, July 31, 2014 5:47 PM
  • Yes, that is because Windows Metro styles app (Windows 8 apps) are better developed for the Touch input, mouse input and keyboard taps were deprecated in Windows 8. 

    That is why you're facing this problem.


    ~!Firewall!~

    Thursday, July 31, 2014 5:56 PM