This project is read-only.

Constants for keyboard input?

Jul 7, 2011 at 8:44 PM

I'm trying to find if there are constants defined for the keys during keyboard input, such as CTRL, ESC, i.e.: 

if (key == NuclexKey.Escape) { // do something }

or do I just have to use their char equivalent, like 

if (key == 27) { // do something }


Or can I somehow use the Windows constants? What is the best way to do this?

Jul 7, 2011 at 9:12 PM

From what I can see after a quick search through the Nuclex.Input assembly, there doesn't seem to be any constants. You should probably be able to use the Window constants though. You can always try and see! :D

Jul 8, 2011 at 2:29 AM
Edited Jul 8, 2011 at 2:42 AM

Keys Enumeration comes from the XNA Framework itself at  Microsoft.Xna.Framework.Input

An example:

   if (Keyboard.GetState().IsKeyDown(Keys.Escape))

Link here to see the list:  Keys Enumeration

Jul 8, 2011 at 4:13 AM
Edited Jul 8, 2011 at 4:13 AM

Well, that is the standard XNA way of doing it, but Nuclex is advertised as having "buffered input" and the method above doesn't work in that case. 

Looking through the Nuclex docs and experimenting I've found that this works:


public void keyboardCharacterEntered(char character)
     if (character == (char) Keys.Escape)


But although it works, it isn't right because Keys is an enumeration, and enums can't be of type char. So, I'm still not sure if casting it this way will work for everything or if it will truncate data in some cases.

Jul 8, 2011 at 9:14 AM

The CharacterEntered event provides you with the translated *character* - meaning text - that you can add to an input field.

While it does seem to translate some special keys (such as escape or backspace), it's not ideal and you should prefer the IKeyboard.KeyPressed event for that purpose - it provides a standard Xna Keys enumeration value.