core/vgui/vgui_key.cxx
Go to the documentation of this file.
00001 // This is core/vgui/vgui_key.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 #include "vgui_key.h"
00006 #include <vcl_iostream.h>
00007 //:
00008 // \file
00009 // \brief  See vgui_key.h for a description of this file.
00010 
00011 //----------------------------------------------------------------------------
00012 //: Convert key from lower case to upper case if necessary.
00013 vgui_key vgui_key_CTRL(int character)
00014 {
00015   if (character >= 'A' && character <= 'Z')
00016     return vgui_key(character - '@');
00017   else
00018     return vgui_key(character - 'a' + 'A' - '@');
00019 }
00020 
00021 //----------------------------------------------------------------------------
00022 vcl_ostream& operator<<(vcl_ostream& s, vgui_key k)
00023 {
00024   int ik = int(k);
00025   s << ik << '/';
00026   if (ik < 0)
00027     return s << "[Bad key, code " << ik << "]";
00028   else if (ik < 27)
00029     return s << "^" << char(ik + '@');
00030   else if (ik < 256)
00031     return s << char(ik);
00032   else if (ik >= vgui_F1 && ik <= vgui_INSERT) {
00033     static char const* names[] = {
00034       "F1", "F2" , "F3" , "F4" , // function keys
00035       "F5", "F6" , "F7" , "F8" ,
00036       "F9", "F10", "F11", "F12",
00037       "CURSOR_LEFT", "CURSOR_UP", "CURSOR_RIGHT",
00038         "CURSOR_DOWN", // cursor movement
00039       "PAGE_UP", "PAGE_DOWN",
00040       "HOME", "END",
00041       "DELETE", "INSERT"  // other things
00042     };
00043     return s << names[ik - int(vgui_F1)];
00044   } else
00045     return s << "[Bad key, code " << ik << "]";
00046 }