[Solved] Use Number keys on the right side.

wilsonwing

02-07-2009 13:18:43

I am not sure how to call it...Right hand side of the keyboard.....look like this:

NumLock / * -
7 8 9 +
4 5 6
1 2 3 Enter
0 .

I tried to use this part for keyboard input, but looks like it doesn't work.
(The playpen demo seems doesn't recive the input, neither)
Do I need to do some extra work to make it able to recive input, or it is not able to use originally? :?
If not, I think is a good idea to make this part inputable. :D

kungfoomasta

02-07-2009 18:26:57

Ah yes I remember this. I need to add the keycodes to the default list of supported key codes, then it will work. I'll add this in and update the zip release, tonight probably.

kungfoomasta

04-07-2009 08:04:19

Sorry for slowness of getting this in, it was actually more complicated than I thought. As it turns out, OIS doesn't give the correct text when pressing NumPad buttons, the unicode char '0' is returned for everything. Since I wanted to help QuickGUI users out with this, I decided to implement a method for QuickGUI to process NumPad KeyCode's and inject Characters if the NumLock state is set. This is all configurable of course, so users who have implemented ways to inject numpad correctly can use the system as it works today, but they will need to set some of the GUIManager's desc options to false (before creation of the GUIManager obviously), since they default to true.

The code I've written so far works, but I need to test it a little more before I submit and update.

wilsonwing

04-07-2009 09:59:03

Sorry for slowness of getting this in, it was actually more complicated than I thought. As it turns out, OIS doesn't give the correct text when pressing NumPad buttons, the unicode char '0' is returned for everything. Since I wanted to help QuickGUI users out with this, I decided to implement a method for QuickGUI to process NumPad KeyCode's and inject Characters if the NumLock state is set. This is all configurable of course, so users who have implemented ways to inject numpad correctly can use the system as it works today, but they will need to set some of the GUIManager's desc options to false (before creation of the GUIManager obviously), since they default to true.

The code I've written so far works, but I need to test it a little more before I submit and update.

I will wait to the day you release it! (Probably really soon) :wink:

kungfoomasta

04-07-2009 21:43:25

The following properties have been added to the GUIManager desc:


// Tells GUIManager if it should watch for NumPad KeyCodes (which aren't translated by OIS correctly) and inject characters
bool injectNumPadKeyCodesAsUnicodeChars;
// Tells GUIManager if it should check NumPad KeyCodes and translate them to Navigational KeyCodes. (Home/End/PgUp/etc.)
bool processNumPadKeyCodes;


And the following public APIs have been added to GUIManager class:


/**
* Returns true if GUIManager watches for NumPad KeyCodes (which aren't translated by OIS correctly) and inject characters.
* NOTE: injection of characters will be called inside injectKeyPressed function.
*/
bool getInjectNumPadKeyCodesAsUnicodeChars();

/**
* Gets if GUIManager checks NumPad KeyCodes and translate them to Navigational KeyCodes. (Home/End/PgUp/etc.)
*/
bool getProcessNumPadKeyCodes();
/**
* Returns true if NumLock is set to on state, false if set to off state.
*/
bool getNumLock();

/**
* If set true, GUIManager will watch for NumPad KeyCodes (which aren't translated by OIS correctly) and inject characters.
* NOTE: injection of characters will be called inside injectKeyPressed function.
*/
void setInjectNumPadKeyCodesAsUnicodeChars(bool inject);
/**
* Sets NumLock to on/off state.
*/
void setNumLock(bool on);
/**
* Sets if GUIManager checks NumPad KeyCodes and translate them to Navigational KeyCodes. (Home/End/PgUp/etc.)
*/
void setProcessNumPadKeyCodes(bool process);


Note that pressing the NumLock key will toggle the NumLock state automatically, but it can also be set manually. (by default its off) I don't know how to determine if the KeyBoard has NumLock down initially. If anybody knows a good solution for this, that would be helpful. Otherwise its up to the user to figure this out and update the GUIManager accordingly.

Also note by default all the numpad functionality I wrote is enabled, so you can set the NumLock state on and things should work for the common case. :)

Zip has been updated.

wilsonwing

05-07-2009 01:58:03

The following properties have been added to the GUIManager desc:


// Tells GUIManager if it should watch for NumPad KeyCodes (which aren't translated by OIS correctly) and inject characters
bool injectNumPadKeyCodesAsUnicodeChars;
// Tells GUIManager if it should check NumPad KeyCodes and translate them to Navigational KeyCodes. (Home/End/PgUp/etc.)
bool processNumPadKeyCodes;


And the following public APIs have been added to GUIManager class:


/**
* Returns true if GUIManager watches for NumPad KeyCodes (which aren't translated by OIS correctly) and inject characters.
* NOTE: injection of characters will be called inside injectKeyPressed function.
*/
bool getInjectNumPadKeyCodesAsUnicodeChars();

/**
* Gets if GUIManager checks NumPad KeyCodes and translate them to Navigational KeyCodes. (Home/End/PgUp/etc.)
*/
bool getProcessNumPadKeyCodes();
/**
* Returns true if NumLock is set to on state, false if set to off state.
*/
bool getNumLock();

/**
* If set true, GUIManager will watch for NumPad KeyCodes (which aren't translated by OIS correctly) and inject characters.
* NOTE: injection of characters will be called inside injectKeyPressed function.
*/
void setInjectNumPadKeyCodesAsUnicodeChars(bool inject);
/**
* Sets NumLock to on/off state.
*/
void setNumLock(bool on);
/**
* Sets if GUIManager checks NumPad KeyCodes and translate them to Navigational KeyCodes. (Home/End/PgUp/etc.)
*/
void setProcessNumPadKeyCodes(bool process);


Note that pressing the NumLock key will toggle the NumLock state automatically, but it can also be set manually. (by default its off) I don't know how to determine if the KeyBoard has NumLock down initially. If anybody knows a good solution for this, that would be helpful. Otherwise its up to the user to figure this out and update the GUIManager accordingly.

Also note by default all the numpad functionality I wrote is enabled, so you can set the NumLock state on and things should work for the common case. :)

Zip has been updated.


So basicly I have to do this when setup:

pGuiManager->setInjectNumPadKeyCodesAsUnicodeChars(true);
pGuiManager->setProcessNumPadKeyCodes(true);


And doesn't need to change anything here:

pGUIManager->injectChar(static_cast<Ogre::UTFString::unicode_char>(e.text));
pGUIManager->injectKeyDown(static_cast<QuickGUI::KeyCode>(e.key));


Do i think it right?

ps. I think is a good idea to put this in the play pen demo :D

kungfoomasta

05-07-2009 19:54:33

One thing I forgot to do is use the desc properties injectNumPadKeyCodesAsUnicodeChars and processNumPadKeyCodes when initializing the GUIManager, I've fixed this now. With this code, you won't have to do anything different, and you will have NumLock support. If you want to disable support, you can set the desc properties previously mentioned to false, and pass the desc in for GUIManager creation. Or you can call the APIs and supply 'false', and it will disable NumLock support.

So in your situation the only code you will want to add is

pGuiManager->setNumLock(true);

I will update the zip within 2 hours or so. I'll make a post on that thread so its more obvious when its been updated. :)