1 // keyboard.cxx -- handle GLUT keyboard events
3 // Written by Curtis Olson, started May 1997.
5 // Copyright (C) 1997 - 1999 Curtis L. Olson - curt@flightgear.org
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36 #include <simgear/compiler.h>
38 #include <Input/input.hxx>
40 #include "keyboard.hxx"
44 * Construct the modifiers.
46 static inline int get_mods ()
48 int glut_modifiers = glutGetModifiers();
51 if (glut_modifiers & GLUT_ACTIVE_SHIFT)
52 modifiers |= FGInput::FG_MOD_SHIFT;
53 if (glut_modifiers & GLUT_ACTIVE_CTRL)
54 modifiers |= FGInput::FG_MOD_CTRL;
55 if (glut_modifiers & GLUT_ACTIVE_ALT)
56 modifiers |= FGInput::FG_MOD_ALT;
63 * Key-down event handler for Glut.
65 * <p>Pass the value on to the FGInput module unless PUI wants it.</p>
67 * @param k The integer value for the key pressed.
71 void GLUTkey(unsigned char k, int x, int y)
73 // Give PUI a chance to grab it first.
74 if (!puKeyboard(k, PU_DOWN))
75 current_input.doKey(k, get_mods(), x, y);
80 * Key-up event handler for GLUT.
82 * <p>PUI doesn't use this, so always pass it to the input manager.</p>
84 * @param k The integer value for the key pressed.
88 void GLUTkeyup(unsigned char k, int x, int y)
90 current_input.doKey(k, get_mods()|FGInput::FG_MOD_UP, x, y);
95 * Special key-down handler for Glut.
97 * <p>Pass the value on to the FGInput module unless PUI wants it.
98 * The key value will have 256 added to it.</p>
100 * @param k The integer value for the key pressed (will have 256 added
105 void GLUTspecialkey(int k, int x, int y)
107 // Give PUI a chance to grab it first.
108 if (!puKeyboard(k + PU_KEY_GLUT_SPECIAL_OFFSET, PU_DOWN))
109 current_input.doKey(k + 256, get_mods(), x, y);
114 * Special key-up handler for Glut.
116 * @param k The integer value for the key pressed (will have 256 added
121 void GLUTspecialkeyup(int k, int x, int y)
123 current_input.doKey(k + 256, get_mods()|FGInput::FG_MOD_UP, x, y);
127 // end of keyboard.cxx