How does the Murl Engine handle keyboard support?
Keyboard Support
|
||||||||||||||||||
(26 Mar 2013, 15:46)stranger Wrote: How does the Murl Engine handle keyboard support? The Murl Engine provides two possible ways to process keyboard events. RawKeys The Murl::Input::IRawKeyboardDevice can be used to obtain the status of physical keys on the keyboard – we call them "raw keys". The definition for raw key codes can be found in the file murl_raw_key_codes.h:
The file should contain a RAWKEY_… definition for every possible physical key. The list includes e.g. RAWKEY_0, RAWKEY_KEYPAD_0, RAWKEY_LEFT_SHIFT, RAWKEY_KEYPAD_NUMLOCK, RAWKEY_VOLUME_UP, RAWKEY_KANJI etc. If you press on an English keyboard the key Y you will get events for RAWKEY_Y. The same key is labeled with Z on a German keyboard. Nevertheless if you press the key Z on a German keyboard you will get events for RAWKEY_Y because it is the same physical button with the same key code. If you press the two keys left SHIFT and Y you will get events for both keys RAWKEY_Y and RAWKEY_LEFT_SHIFT. To obtain the status for physical keyboard input, you can use the device handler's WasRawKeyPressed() method.
In addition to WasRawKeyPressed(), physical keyboard input is also reflected by the IsRawKeyPressed() and WasRawKeyReleased() methods. During a regular keystroke, these methods return true in the following sequence:
Please note that the framework do not report raw keys for non-physical keyboards e.g. touch screen keyboards on mobile devices. Vanilla Keys The Murl::Input::IKeyboardDevice can be used to obtain the character value of a keystroke after the operating system processed the key codes – we call them "vanilla keys". While the IRawKeyboardDevice only reports key states, the IKeyboardDevice reports the UTF8 encoded character representation of a keystroke. The result depends for example on your language settings. If you press the key Y you will get a lowercase y if the language is set to English. If you press the two keys SHIFT and Y you will get uppercase Y. If the language is set to German you will get z or Z respectively. You can use the the device handler's GetNumberOfKeys, GetKey and GetKeys methods to obtain the UTF8 character representation.
How can I detect if any keyboard key is currently being pressed? I'm not interested in what the key is.
(13 Apr 2013, 7:23)stranger Wrote: How can I detect if any keyboard key is currently being pressed? I'm not interested in what the key is. You have to iterate through the Rawkey enum:
In addition you can use the function GetEnumName to get a name for the RawKey:
The output for RAWKEY_A, RAWKEY_LEFT_CONTROL and RAWKEY_LEFT_SHIFT would be:
Since Murl Engine Version 1.00.2194 it is possible to get a Map containing the key/value pairs for all Murl enums. The corresponding methods are:
The map makes it easy to iterate through the enum. The code above to iterate through the RawKey enum would change to:
Please note that this is the preferred way. Iterating through the map guarantees that only valid enum values are used even if the enum contains “holes”. Consider the following enum:
The previous version would iterate through all values from 1 to 99 while the new version only considers the two valid values. | ||||||||||||||||||
« Next Oldest | Next Newest »
|