Browse Source

extend ascii_key to accept a string as well as a character

David Rose 24 years ago
parent
commit
2b080112c3
2 changed files with 18 additions and 0 deletions
  1. 17 0
      panda/src/putil/keyboardButton.cxx
  2. 1 0
      panda/src/putil/keyboardButton.h

+ 17 - 0
panda/src/putil/keyboardButton.cxx

@@ -33,6 +33,23 @@ ascii_key(char ascii_equivalent) {
   return ButtonRegistry::ptr()->find_ascii_button(ascii_equivalent);
 }
 
+////////////////////////////////////////////////////////////////////
+//     Function: KeyboardButton::ascii_key
+//       Access: Public, Static
+//  Description: Returns the ButtonHandle associated with the
+//               particular ASCII character (taken from the first
+//               character of the indicated string), if there is one,
+//               or ButtonHandle::none() if there is not.
+////////////////////////////////////////////////////////////////////
+ButtonHandle KeyboardButton::
+ascii_key(const string &ascii_equivalent) {
+  if (ascii_equivalent.empty()) {
+    return ButtonHandle::none();
+  } else {
+    return ButtonRegistry::ptr()->find_ascii_button(ascii_equivalent[0]);
+  }
+}
+
 #define DEFINE_KEYBD_BUTTON_HANDLE(KeyName)     \
                   static ButtonHandle _##KeyName; \
                   ButtonHandle KeyboardButton::KeyName() { return _##KeyName; }

+ 1 - 0
panda/src/putil/keyboardButton.h

@@ -32,6 +32,7 @@
 class EXPCL_PANDA KeyboardButton {
 PUBLISHED:
   static ButtonHandle ascii_key(char ascii_equivalent);
+  static ButtonHandle ascii_key(const string &ascii_equivalent);
 
   static ButtonHandle space();
   static ButtonHandle backspace();