a bit more osx keyboard/mouse support

This commit is contained in:
David Rose 2006-10-09 23:47:08 +00:00
parent ff6a4155ee
commit 9744dbfc0b
4 changed files with 51 additions and 18 deletions

View File

@ -1325,7 +1325,7 @@ void osxGraphicsWindow::SystemSetWindowForground(bool forground)
case 121: nk = KeyboardButton::page_down(); break; case 121: nk = KeyboardButton::page_down(); break;
case 115: nk = KeyboardButton::home(); break; case 115: nk = KeyboardButton::home(); break;
case 119: nk = KeyboardButton::end(); break; case 119: nk = KeyboardButton::end(); break;
// case : nk = KeyboardButton::insert(); break; case 114: nk = KeyboardButton::help(); break;
case 117: nk = KeyboardButton::del(); break; case 117: nk = KeyboardButton::del(); break;
// case 71: nk = KeyboardButton::num_lock() break; // case 71: nk = KeyboardButton::num_lock() break;
@ -1358,13 +1358,18 @@ void osxGraphicsWindow::SystemSetWindowForground(bool forground)
case 44: nk = KeyboardButton::ascii_key('/'); break; case 44: nk = KeyboardButton::ascii_key('/'); break;
default: default:
// printf (" Untranslated KeyCode: %lu (0x%lX)\n", key, key); if (osxdisplay_cat.is_debug()) {
// not sure this is right .. but no mapping for keypad and such osxdisplay_cat.debug()
// this at least does a best gess.. << " Untranslated KeyCode: " << key
<< " (0x" << hex << key << dec << ")\n";
}
char charCode = 0; // not sure this is right .. but no mapping for keypad and such
if(GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, nil, sizeof( charCode ), nil, &charCode ) == noErr) // this at least does a best gess..
nk = KeyboardButton::ascii_key(charCode);
char charCode = 0;
if(GetEventParameter( event, kEventParamKeyMacCharCodes, typeChar, nil, sizeof( charCode ), nil, &charCode ) == noErr)
nk = KeyboardButton::ascii_key(charCode);
} }
return nk; return nk;
} }
@ -1386,6 +1391,9 @@ void osxGraphicsWindow::SystemSetWindowForground(bool forground)
if ((changed & (controlKey | rightControlKey)) != 0) if ((changed & (controlKey | rightControlKey)) != 0)
SendKeyEvent(KeyboardButton::control(),(newModifiers & (controlKey | rightControlKey)) != 0); SendKeyEvent(KeyboardButton::control(),(newModifiers & (controlKey | rightControlKey)) != 0);
if ((changed & cmdKey) != 0)
SendKeyEvent(KeyboardButton::meta(),(newModifiers & cmdKey) != 0);
if ((changed & alphaLock) != 0) if ((changed & alphaLock) != 0)
SendKeyEvent(KeyboardButton::caps_lock(),(newModifiers & alphaLock) != 0); SendKeyEvent(KeyboardButton::caps_lock(),(newModifiers & alphaLock) != 0);

View File

@ -82,6 +82,7 @@ DEFINE_KEYBD_BUTTON_HANDLE(home)
DEFINE_KEYBD_BUTTON_HANDLE(end) DEFINE_KEYBD_BUTTON_HANDLE(end)
DEFINE_KEYBD_BUTTON_HANDLE(insert) DEFINE_KEYBD_BUTTON_HANDLE(insert)
DEFINE_KEYBD_BUTTON_HANDLE(del) DEFINE_KEYBD_BUTTON_HANDLE(del)
DEFINE_KEYBD_BUTTON_HANDLE(help)
DEFINE_KEYBD_BUTTON_HANDLE(meta) DEFINE_KEYBD_BUTTON_HANDLE(meta)
DEFINE_KEYBD_BUTTON_HANDLE(caps_lock) DEFINE_KEYBD_BUTTON_HANDLE(caps_lock)
DEFINE_KEYBD_BUTTON_HANDLE(shift_lock) DEFINE_KEYBD_BUTTON_HANDLE(shift_lock)
@ -142,6 +143,7 @@ init_keyboard_buttons() {
ButtonRegistry::ptr()->register_button(_home, "home"); ButtonRegistry::ptr()->register_button(_home, "home");
ButtonRegistry::ptr()->register_button(_end, "end"); ButtonRegistry::ptr()->register_button(_end, "end");
ButtonRegistry::ptr()->register_button(_insert, "insert"); ButtonRegistry::ptr()->register_button(_insert, "insert");
ButtonRegistry::ptr()->register_button(_help, "help");
ButtonRegistry::ptr()->register_button(_shift, "shift"); ButtonRegistry::ptr()->register_button(_shift, "shift");
ButtonRegistry::ptr()->register_button(_control, "control"); ButtonRegistry::ptr()->register_button(_control, "control");

View File

@ -63,6 +63,7 @@ PUBLISHED:
static ButtonHandle end(); static ButtonHandle end();
static ButtonHandle insert(); static ButtonHandle insert();
static ButtonHandle del(); // delete is a C++ keyword. static ButtonHandle del(); // delete is a C++ keyword.
static ButtonHandle help();
static ButtonHandle shift(); static ButtonHandle shift();
static ButtonHandle control(); static ButtonHandle control();

View File

@ -25,6 +25,7 @@
#include "modifierButtons.h" #include "modifierButtons.h"
#include "linmath_events.h" #include "linmath_events.h"
#include "mouseButton.h" #include "mouseButton.h"
#include "keyboardButton.h"
TypeHandle Trackball::_type_handle; TypeHandle Trackball::_type_handle;
@ -32,8 +33,6 @@ TypeHandle Trackball::_type_handle;
#define B1_MASK 0x01 #define B1_MASK 0x01
#define B2_MASK 0x02 #define B2_MASK 0x02
#define B3_MASK 0x04 #define B3_MASK 0x04
#define B4_MASK 0x08
#define B5_MASK 0x10
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
// Function: Trackball::Constructor // Function: Trackball::Constructor
@ -66,8 +65,14 @@ Trackball(const string &name) :
watch_button(MouseButton::one()); watch_button(MouseButton::one());
watch_button(MouseButton::two()); watch_button(MouseButton::two());
watch_button(MouseButton::three()); watch_button(MouseButton::three());
watch_button(MouseButton::four());
watch_button(MouseButton::five()); // In OSX mode, we need to use the command and option key in
// conjunction with the (one) mouse button. We can go ahead and
// keep this code live in other platforms too; it doesn't do any
// harm.
watch_button(KeyboardButton::meta());
watch_button(KeyboardButton::alt());
watch_button(KeyboardButton::control());
} }
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
@ -553,7 +558,30 @@ do_transmit_data(DataGraphTraverser *, const DataNodeTransmit &input,
int this_button = 0; int this_button = 0;
if (is_down(MouseButton::one())) { if (is_down(MouseButton::one())) {
this_button |= B1_MASK; if (is_down(KeyboardButton::meta())) {
// Wait, the user is holding down the command key in
// conjunction with mouse button 1. This changes its meaning
// to either mouse 2 and/or mouse 3, according to whether the
// alt or control key is also held down.
if (is_down(KeyboardButton::alt())) {
// Command + alt: B2 + B3.
this_button |= B2_MASK | B3_MASK;
} else if (is_down(KeyboardButton::control())) {
// Command + control: B2.
this_button |= B2_MASK;
} else {
// Command key by itself: B3.
this_button |= B3_MASK;
}
} else {
// Without the command key, a mouse 1 button is a mouse 1
// button.
this_button |= B1_MASK;
}
} }
if (is_down(MouseButton::two())) { if (is_down(MouseButton::two())) {
this_button |= B2_MASK; this_button |= B2_MASK;
@ -561,12 +589,6 @@ do_transmit_data(DataGraphTraverser *, const DataNodeTransmit &input,
if (is_down(MouseButton::three())) { if (is_down(MouseButton::three())) {
this_button |= B3_MASK; this_button |= B3_MASK;
} }
if (is_down(MouseButton::four())) {
this_button |= B4_MASK;
}
if (is_down(MouseButton::five())) {
this_button |= B5_MASK;
}
float x = this_x - _lastx; float x = this_x - _lastx;
float y = this_y - _lasty; float y = this_y - _lasty;