Game Development Reference
In-Depth Information
// Number 3 key has just been pressed
}
else
{
// Number 3 key has just been released
}
}
}
// We use this to register the callback function…
s3eKeyboardRegister(S3E_KEYBOARD_KEY_EVENT,
(s3eCallback) KeyStateCallback, NULL);
// …and this to cancel notifications
s3eKeyboardUnRegister(S3E_KEYBOARD_KEY_EVENT,
(s3eCallback) KeyStateCallback);
The method of key press detection to be used is really down to project requirements
and personal preference. Since a call to s3eKeyboardUpdate will cache the state of
every key for us, a polled approach may be best if we need to detect the current state
of several keys at any time. A callback approach may be better if we just want to
respond immediately to a key press and are less interested in tracking the key's state
beyond this.
Detecting character code input
The s3eKeyboard API also provides support for reading character codes from the
keyboard. With this approach, we don't receive any notification of when a key
was pressed or released. Instead, we receive a stream of character codes which
automatically take into account any special modifier keys; so if a user pressed the
Shift key, followed by the A key, then released both these keys, we would only
receive the character code for a capital letter A.
This approach is probably less useful for most games due to it not being an
immediate form of notification, especially since fewer and fewer devices now
feature physical keys that can be pressed.
Not all devices support this input method, so you should use a call to
s3eKeyboardGetInt(S3E_KEYBOARD_GET_CHAR) to determine if it can be used.
For the sake of completeness though, let us look at how we can receive character
codes using either polling or callbacks.
 
Search WWH ::




Custom Search