Click here to Skip to main content
15,887,386 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I am writing a game engine for UWP. I have a code snippet taken from XNA, checking for if a certain key is pressed (see below). In my game engine I'd rather not use the dedicated event handlers (KeyDown etc), but instead simply check for pressed keys in my game loop. One reason for this is that I can then control for example how often a bullet fires if the key is continuously pressed (using a timer and mod). It would also let the keys be independent of each other, such as up and right arrow key gives diagonal movement for player A, while another player (using the same keyboard) uses keys A and W to move his/her character in another direction, and they both occasionally fire their laser guns.


The code I have found looks like this:

public void DrawHelp()
       {
           if (Keyboard.GetState().IsKeyDown(Keys.Tab))
           {


What I'm thinking of is basically a series of if statements (the code is wrong - it's just to show what I want):

 public void CheskKeysPressed()
        {
            if (Keyboard.GetState().KeyDown.Holds(Keys.Right) &&
(Keyboard.GetState().KeyDown.Holds(Keys.Up))
            { //diagonal move


So, is it possible to write something like this in UWP, and if so: How?

Thanks!

Petter

What I have tried:

I've done some searching on Bing and Google for this, but there is still very little info on UWP.
Posted
Updated 31-Dec-16 8:45am

Same issue as your previous question: What is the smartest way to detect keypresses in uwp?[^].
 
Share this answer
 
I got a good reply here: c# - Detecting keys pressed without events in UWP - Stack Overflow[^]

Hope it can help anyone with the same problem.

Happy New Year!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900