Bochs/bochs/gui/keymap.h
Bryce Denney c74b8c55fc - add key mapping for SDL gui, to demonstrate/verify that key mapping is not
specific to X windows.  I changed a few names of variables and methods to
  sound less X windows specific, for example in the BXKeyEntry struct
  the "xwinKey" field is now called "hostKey".
- remove the hacks in bx_keymap_c::loadKeymap that checked that every
  keysym started with "XK_".  Now I can still make that check, but it
  is done in x.cc's convertStringToXKeysym() instead.
- in sdl.cc, load the keymap in specific_init function.  I had to
  create a conversion function from SDL key names to SDLkey values.
  I created a table of key names and associated values, and I just
  do a strcmp on each name.  It's not a fast algorithm obviously but this
  conversion only has to be done for maybe 200 keys at startup time.
- added a key map file for SDL called sdl-pc-us.map.  Since this has
  basically all the SDLK_* symbols defined, it is a good starting point
  if you need to make any other keymaps.
- modified: gui/keymap.cc gui/keymap.h gui/sdl.cc gui/x.cc iodev/keyboard.cc
- added: gui/sdlkeys.h gui/keymaps/sdl-pc-us.map
2002-10-08 06:14:53 +00:00

77 lines
2.8 KiB
C++

/////////////////////////////////////////////////////////////////////////
// $Id: keymap.h,v 1.6 2002-10-08 06:14:52 bdenney Exp $
/////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2002 MandrakeSoft S.A.
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
/////////////////////////////////////////////////////////////////////////
//
// Methods of bx_keymap_c :
//
// - loadKeymap(Bit32u convertStringToSymbol(const char*));
// loads the configuration specified keymap file if keymapping is enabled
// using convertStringToSymbol to convert strings to client constants
//
// - loadKeymap(Bit32u convertStringToSymbol(const char*), const char* filename);
// loads the specified keymap file
// using convertStringToSymbol to convert strings to client constants
//
// - isKeymapLoaded () returns true if the keymap contains any valid key
// entries.
//
// - convertStringToBXKey
// convert a null-terminate string to a BX_KEY code
//
// - findHostKey(Bit32u key)
// - findAsciiChar(Bit8u ch)
// Each of these methods returns a pointer to a BXKeyEntry structure
// corresponding to a key. findHostKey() finds an entry whose hostKey
// value matches the target value, and findAsciiChar() finds an entry
// whose ASCII code matches the search value.
// In case of unknown symbol
#define BX_KEYMAP_UNKNOWN 0xFFFFFFFF
// Structure of an element of the keymap table
typedef struct {
Bit32u baseKey; // base key
Bit32u modKey; // modifier key that must be held down
Bit32s ascii; // ascii equivalent, if any
Bit32u hostKey; // value that the host's OS or library recognizes
} BXKeyEntry;
class bx_keymap_c : public logfunctions {
public:
bx_keymap_c(void);
~bx_keymap_c(void);
void loadKeymap(Bit32u(*)(const char*));
void loadKeymap(Bit32u(*)(const char*),const char *filename);
Boolean isKeymapLoaded ();
BXKeyEntry *findHostKey(Bit32u hostkeynum);
BXKeyEntry *findAsciiChar(Bit8u ascii);
private:
Bit32u convertStringToBXKey(const char *);
BXKeyEntry *keymapTable;
Bit16u keymapCount;
};
extern bx_keymap_c bx_keymap;