XNA number lock affects input

I have an interrupt which on the keyboard gives me a coordinating key. When number lock is turned on, keys appear as Numpad1, Numpad2, etc. When the number lock is turned off, the numpad keys turn into End, Left, Right, Up, PageLock ... I cannot do this because I need to hold these keys (left, right ..) as actual arrow keys. The identifier most likely does not affect the blocking of the number. However, I cannot mitigate this as I receive input from XNA directly. Can anyone confirm that this is happening in XNA 3.1 on VS 2008?

+2
source share
3 answers

XNA internally uses the win32 function GetKeyboardState to determine the state of the keyboard. This function cannot distinguish between the numeric keypad, the arrow keys, and the insert group.

Apparently, you can distinguish keys using the WM_KEYDOWN message (and his friends).

I will leave the gap needed to receive win32 messages in the XNA application, and how to check the data for the message as an exercise.

(Personally, I would recommend just changing your control scheme or just observing the state of a custom num-lock. Generally speaking, it is a bad idea to take on the functionality of something like the num-lock key!)

+2
source

You can define 2 keys for each action in your game.

For example, instead of Keys.Left, to move left, select another key (Numpad4).

In the input validation code, you just check if any of these two keys are pressed:

For instance:

 if (IsKeyPressed(Keys.Numpad4) || IsKeyPressed(Keys.Left) { // Do some action. } 

You can also create a method that takes 2 keys and executes it internally, without having to write code every time.

0
source

I haven't confirmed this yet, but Ryan Rubley from Morpheus Development has posted a solution worth checking out:

http://xboxforums.create.msdn.com/forums/p/90944/545124.aspx#545124

Here is a fully working solution for using numpad keys regardless of numlock and without enabling numlock

Created by Ryan Rubley 9-5-2011

0
source

Source: https://habr.com/ru/post/1496074/


All Articles