Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Examples  

gadget::EventWindowWin32 Class Reference

#include <EventWindowWin32.h>

Inheritance diagram for gadget::EventWindowWin32:

Inheritance graph
[legend]
Collaboration diagram for gadget::EventWindowWin32:

Collaboration graph
[legend]
List of all members.

Public Types

enum  lockState { Unlocked, Lock_LockKey, Lock_KeyDown }
 < Enum to keep track of current lock state for state machine. More...


Public Methods

 EventWindowWin32 ()
virtual ~EventWindowWin32 ()
virtual bool config (jccl::ConfigElementPtr e)
void controlLoop (void *nullParam)
 Main thread of control for this active object. More...

bool startSampling ()
 Start a device sampling. More...

bool stopSampling ()
 StopSampling. More...

bool sample ()
 Processes the current events. More...

void updateData ()
 Update the data. More...

int isKeyPressed (int Key)
 Returns the number of times the key was pressed during the last frame. More...

void operator delete (void *p)
 Invokes the global scope delete operator. More...


Static Public Methods

std::string getElementType ()
 Returns the string rep of the element type used to config this device. More...


Protected Methods

void destroy ()
 Deletes this object. More...

virtual void processEvent (UINT message, UINT wParam, LONG lParam)
void addKeyEvent (const gadget::Keys &key, const gadget::EventType &type, const MSG &message)
void addMouseButtonEvent (const gadget::Keys &button, const gadget::EventType &type, const MSG &message)
void addMouseMoveEvent (const MSG &message)
void lockMouse ()
void unlockMouse ()
void createWindowWin32 ()
void updKeys (const MSG &message)
void handleEvents ()
 Handles any events in the system. More...

Private functions for processing input data
int onlyModifier (int)
Windows utility functions
gadget::Keys VKKeyToKey (int vkKey)
char * checkArgs (char *look_for)
BOOL MenuInit (HINSTANCE hInstance)

Protected Attributes

HINSTANCE m_hInst
HWND m_hWnd
bool mWeOwnTheWindow
 True if this class owns the window (is reposible for opening, closing, and event processing). More...

int mScreen
int mX
int mY
 screen id, x-origin, y-origin. More...

unsigned int mWidth
unsigned int mHeight
int mKeys [gadget::LAST_KEY]
 (0,*): The num key presses during an UpdateData (ie. More...

int mRealkeys [gadget::LAST_KEY]
 (0,1): The real keyboard state, all events processed (ie. More...

vpr::Mutex mKeysLock
 Must hold this lock when accessing mKeys. More...

bool mExitFlag
 Should we exit? More...

lockState mLockState
 The current state of locking. More...

int mLockStoredKey
 The key that was pressed down. More...

int mLockToggleKey
 The key that toggles the locking. More...

float mMouseSensitivity
int mSleepTimeMS
 Amount of time to sleep in milliseconds between updates. More...

int mPrevX
int mPrevY
 Previous mouse location. More...

bool mControlLoopDone

Friends

LONG APIENTRY MenuWndProc (HWND hWnd, UINT message, UINT wParam, LONG lParam)

Member Enumeration Documentation

enum gadget::EventWindowWin32::lockState
 

< Enum to keep track of current lock state for state machine.

Enumeration values:
Unlocked  The mouse is free.
Lock_LockKey  The mouse is locked due to lock toggle key press.
Lock_KeyDown  The mouse is locked due to a key being held down.

Definition at line 78 of file EventWindowWin32.h.

00079    {
00080       Unlocked,     
00081       Lock_LockKey, 
00082       Lock_KeyDown  
00083    };


Constructor & Destructor Documentation

gadget::EventWindowWin32::EventWindowWin32   [inline]
 

Definition at line 85 of file EventWindowWin32.h.

00086       : mControlLoopDone(false),
00087         mPrevX(0),
00088         mPrevY(0),
00089         mLockState(Unlocked),
00090         mExitFlag(false),
00091         mWeOwnTheWindow(true)
00092    {
00093    }

virtual gadget::EventWindowWin32::~EventWindowWin32   [inline, virtual]
 

Definition at line 95 of file EventWindowWin32.h.

00096    {
00097       stopSampling();
00098    }


Member Function Documentation

bool gadget::EventWindowWin32::config jccl::ConfigElementPtr    e [virtual]
 

Reimplemented from gadget::EventWindow.

Definition at line 54 of file EventWindowWin32.cpp.

References gadgetDBG_INPUT_MGR, Lock_LockKey, gadget::EventWindow::mCurKeys, mHeight, mKeys, mLockState, mLockToggleKey, mMouseSensitivity, mRealkeys, mSleepTimeMS, mWeOwnTheWindow, mWidth, mX, and mY.

00055 {
00056    vpr::DebugOutputGuard dbg_output(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL,
00057                                     std::string("gadget::EventWindowWin32::config() entered\n"),
00058                                     std::string("gadget::EventWindowWin32::config() done\n"));
00059 
00060    // Call base class config function first
00061    if ( ! (Input::config(e) && EventWindow::config(e)) )
00062    {
00063       return false;
00064    }
00065 
00066    for ( int i = 0; i < gadget::LAST_KEY; ++i )
00067    {
00068       mRealkeys[i] = mKeys[i] = mCurKeys[i];
00069    }
00070 
00071    // Get size and position
00072    mWidth  = e->getProperty<int>("width");
00073    mHeight = e->getProperty<int>("height");
00074 
00075    // default to something "sane" if too small
00076    if ( mWidth == 0 ) mWidth = 400;
00077    if ( mHeight == 0 ) mHeight = 400;
00078 
00079    mX = e->getProperty<int>("origin", 0);
00080    mY = e->getProperty<int>("origin", 1);
00081 
00082    // Get the lock information
00083    mLockToggleKey    = e->getProperty<int>("lock_key");
00084    bool start_locked = e->getProperty<bool>("start_locked");
00085 
00086    if ( start_locked )
00087    {
00088       mLockState = Lock_LockKey;     // Initialize to the locked state
00089    }
00090 
00091    mMouseSensitivity = e->getProperty<float>("mouse_sensitivity");
00092 
00093    // Sanity check.
00094    if ( 0.0f == mMouseSensitivity )
00095    {
00096       mMouseSensitivity = 0.5f;
00097    }
00098 
00099    vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_STATE_LVL)
00100       << "Mouse Sensititivty: " << mMouseSensitivity << std::endl
00101       << vprDEBUG_FLUSH;
00102 
00103    mSleepTimeMS = e->getProperty<int>("sleep_time");
00104 
00105    // Sanity check.
00106    if ( mSleepTimeMS == 0 )
00107    {
00108       mSleepTimeMS = 50;
00109    }
00110 
00111    // Default to owning the window
00112    mWeOwnTheWindow = true;
00113 
00114    return true;
00115 }

void gadget::EventWindowWin32::controlLoop void *    nullParam
 

Main thread of control for this active object.

Definition at line 117 of file EventWindowWin32.cpp.

References createWindowWin32, gadgetDBG_INPUT_MGR, Lock_LockKey, lockMouse, mControlLoopDone, mExitFlag, mLockState, mSleepTimeMS, and sample.

00118 {
00119    mControlLoopDone = false;
00120 
00121    // Open the window...
00122    // The Window has to be created in the same thread that
00123    // we run the message pump because all window messages
00124    // dispatched are dispatched to the thread that created
00125    // the window.  (And we want to receive the messages
00126    // in the spawned thread)
00127    this->createWindowWin32();
00128 
00129    // If we have initial locked, then we need to lock the system
00130    if ( mLockState == Lock_LockKey )     // Means that we are in the initially locked state
00131    {
00132       vprDEBUG(gadgetDBG_INPUT_MGR,vprDBG_STATE_LVL)
00133          << "gadget::EventWindowWin32::controlLoop: Mouse set to initial lock. Locking it now.\n"
00134          << vprDEBUG_FLUSH;
00135       this->lockMouse();                // Lock the mouse
00136    }
00137 
00138    // When there are messages, process them all.  Otherwise,
00139    // sleep for a while...
00140    while ( !mExitFlag )
00141    {
00142       this->sample();
00143 
00144       // user-specified sleep time.
00145       vpr::System::usleep(mSleepTimeMS * 1000);
00146    }
00147 
00148    // clean up, delete the window!
00149    ::CloseWindow(m_hWnd); // send a message to the window to close
00150    mControlLoopDone = true;
00151 }

bool gadget::EventWindowWin32::startSampling   [virtual]
 

Start a device sampling.

Start the device sampling, normally this will spawn a thread which will just repeatedly call Sample(). This function should return true when it sucessfully starts, false otherwise.

Implements gadget::Input.

Definition at line 217 of file EventWindowWin32.cpp.

References gadgetDBG_INPUT_MGR, mExitFlag, and gadget::Input::mThread.

00218 {
00219    if ( mThread != NULL )
00220    {
00221       vprDEBUG(vprDBG_ERROR,vprDBG_CRITICAL_LVL)
00222          << clrOutNORM(clrRED,"ERROR:")
00223          << "gadget::EventWindowWin32: startSampling called, when already sampling.\n"
00224          << vprDEBUG_FLUSH;
00225       vprASSERT(mThread == NULL);
00226       return 0;
00227    }
00228 
00229    vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_CONFIG_LVL)
00230       << "gadget::EventWindowWin32::startSampling() : ready to go.."
00231       << std::endl << vprDEBUG_FLUSH;
00232 
00233    // Create a new thread to handle the control
00234    mExitFlag = false;
00235    vpr::ThreadMemberFunctor<EventWindowWin32>* memberFunctor =
00236       new vpr::ThreadMemberFunctor<EventWindowWin32>(this,
00237                                                      &EventWindowWin32::controlLoop,
00238                                                      (void*) this);
00239 
00240    mThread = new vpr::Thread(memberFunctor);
00241 
00242    // return success value...
00243    if ( ! mThread->valid() )
00244    {
00245       return false; // fail
00246    }
00247 
00248    return true; // success
00249 }

bool gadget::EventWindowWin32::stopSampling   [virtual]
 

StopSampling.

Reverse the effects of StartSampling().

Implements gadget::Input.

Definition at line 563 of file EventWindowWin32.cpp.

References m_hWnd, mExitFlag, and gadget::Input::mThread.

00564 {
00565    if ( mThread != NULL )
00566    {
00567       mExitFlag = true;
00568       ::PostMessage( m_hWnd, WM_USER, 0, 0 );// send a dummy message to the window to close
00569       mThread->join();
00570       delete mThread;
00571       mThread = NULL;
00572       //std::cout << "Stopping event window.." << std::endl;
00573    }
00574    return true;
00575 }

bool gadget::EventWindowWin32::sample   [virtual]
 

Processes the current events.

Called repetatively by the controlLoop.

Implements gadget::Input.

Definition at line 795 of file EventWindowWin32.cpp.

References handleEvents.

Referenced by controlLoop.

00796 {
00797    this->handleEvents();
00798    return true;
00799 }

void gadget::EventWindowWin32::updateData   [virtual]
 

Update the data.

After this function is called subsequent calls to GetData(d) will return the most recent data at the time of THIS function call. Data is guaranteed to be valid and static until the next call to UpdateData.

Implements gadget::Input.

Definition at line 269 of file EventWindowWin32.cpp.

References gadget::EventWindow::mCurKeys, mKeys, mKeysLock, mMouseSensitivity, mRealkeys, and gadget::EventWindow::updateEventQueue.

00270 {
00271    vpr::Guard<vpr::Mutex> guard(mKeysLock);     // Lock access to the mKeys array
00272 
00273    // Scale mouse values based on sensitivity
00274    mKeys[gadget::MOUSE_POSX] = int(float(mKeys[gadget::MOUSE_POSX]) * mMouseSensitivity);
00275    mKeys[gadget::MOUSE_NEGX] = int(float(mKeys[gadget::MOUSE_NEGX]) * mMouseSensitivity);
00276    mKeys[gadget::MOUSE_POSY] = int(float(mKeys[gadget::MOUSE_POSY]) * mMouseSensitivity);
00277    mKeys[gadget::MOUSE_NEGY] = int(float(mKeys[gadget::MOUSE_NEGY]) * mMouseSensitivity);
00278 
00279    // Copy over values
00280    for ( unsigned int i = 0; i < gadget::LAST_KEY; ++i )
00281    {
00282       mCurKeys[i] = mKeys[i];
00283    }
00284 
00285    // Re-initialize the mKeys based on current key state in realKeys
00286    // Set the initial state of the mKey key counts based on the current state of the system
00287    // this is to ensure that if a key is still down, we get at least one event for it
00288    for ( unsigned int j = 0; j < gadget::LAST_KEY; ++j )
00289    {
00290       mKeys[j] = mRealkeys[j];
00291    }
00292 
00293    updateEventQueue();
00294 }

std::string gadget::EventWindowWin32::getElementType   [static]
 

Returns the string rep of the element type used to config this device.

This string is used by the device factory to look up device drivers based up the type of element it is trying to load.

Reimplemented from gadget::Input.

Definition at line 801 of file EventWindowWin32.cpp.

00802 {
00803    return "event_window";
00804 }

int gadget::EventWindowWin32::isKeyPressed int    Key
 

Returns the number of times the key was pressed during the last frame.

You can put this in an if to check if was pressed at all, or if you are doing processing based on this catch the actual number.

Definition at line 810 of file EventWindowWin32.cpp.

References gadget::EventWindow::mCurKeys.

00811 {
00812    return mCurKeys[Key];
00813 }

void gadget::EventWindowWin32::operator delete void *    p [inline]
 

Invokes the global scope delete operator.

This is required for proper releasing of memory in DLLs on Win32.

Definition at line 128 of file EventWindowWin32.h.

00129    {
00130       ::operator delete(p);
00131    }

void gadget::EventWindowWin32::destroy   [inline, protected, virtual]
 

Deletes this object.

This is an implementation of the pure virtual gadget::Input::destroy() method.

Implements gadget::Input.

Definition at line 138 of file EventWindowWin32.h.

00139    {
00140       delete this;
00141    }

virtual void gadget::EventWindowWin32::processEvent UINT    message,
UINT    wParam,
LONG    lParam
[inline, protected, virtual]
 

Definition at line 143 of file EventWindowWin32.h.

Referenced by updKeys.

00144    {
00145    }

void gadget::EventWindowWin32::addKeyEvent const gadget::Keys   key,
const gadget::EventType   type,
const MSG &    message
[protected]
 

Definition at line 836 of file EventWindowWin32.cpp.

References gadget::EventWindow::addEvent.

Referenced by updKeys.

00839 {
00840    // XXX: Missing modifier key information here...
00841    // XXX: Missing ASCII character value here...
00842    gadget::EventPtr key_event(new gadget::KeyEvent(type, key, 0, msg.time));
00843    addEvent(key_event);
00844 }

void gadget::EventWindowWin32::addMouseButtonEvent const gadget::Keys   button,
const gadget::EventType   type,
const MSG &    message
[protected]
 

Definition at line 846 of file EventWindowWin32.cpp.

References gadget::EventWindow::addEvent, GET_X_LPARAM, and GET_Y_LPARAM.

Referenced by updKeys.

00849 {
00850    // XXX: Missing keyboard modifier information here...
00851    gadget::EventPtr mouse_event(new gadget::MouseEvent(type, button,
00852                                                        GET_X_LPARAM(msg.lParam),
00853                                                        GET_Y_LPARAM(msg.lParam),
00854                                                        msg.pt.x, msg.pt.y, 0,
00855                                                        msg.time));
00856    addEvent(mouse_event);
00857 }

void gadget::EventWindowWin32::addMouseMoveEvent const MSG &    message [protected]
 

Definition at line 859 of file EventWindowWin32.cpp.

References gadget::EventWindow::addEvent, GET_X_LPARAM, and GET_Y_LPARAM.

Referenced by updKeys.

00860 {
00861    gadget::EventPtr mouse_event(new gadget::MouseEvent(gadget::MouseMoveEvent,
00862                                                        gadget::NO_MBUTTON,
00863                                                        GET_X_LPARAM(msg.lParam),
00864                                                        GET_Y_LPARAM(msg.lParam),
00865                                                        msg.pt.x, msg.pt.y, 0,
00866                                                        msg.time));
00867    addEvent(mouse_event);
00868 }

void gadget::EventWindowWin32::lockMouse   [protected]
 

Definition at line 815 of file EventWindowWin32.cpp.

References m_hWnd, mHeight, and mWidth.

Referenced by controlLoop, and updKeys.

00816 {
00817    // Center the mouse
00818    int win_center_x(mWidth / 2), win_center_y(mHeight / 2);
00819 
00820    // convert windows coords to screen coords.
00821    ::POINT pt;
00822    pt.x = win_center_x;
00823    pt.y = win_center_y;
00824    ::ClientToScreen(m_hWnd, &pt);
00825    ::SetCursorPos(pt.x, pt.y);
00826 
00827    // capture the mouse for this window...
00828    HWND previous_capture = ::SetCapture(m_hWnd);
00829 }

void gadget::EventWindowWin32::unlockMouse   [protected]
 

Definition at line 831 of file EventWindowWin32.cpp.

Referenced by updKeys.

00832 {
00833    BOOL result = ::ReleaseCapture();
00834 }

void gadget::EventWindowWin32::createWindowWin32   [protected]
 

Definition at line 726 of file EventWindowWin32.cpp.

References m_hInst, m_hWnd, MenuInit, mHeight, gadget::Input::mInstName, mWidth, mX, and mY.

Referenced by controlLoop.

00727 {
00728    int root_height;
00729 
00730    InitCommonControls();
00731 
00732    //m_hInst = g_hInst;
00733    m_hInst = GetModuleHandle(NULL);   // Just try to get the application's handle
00734    MenuInit(m_hInst);
00735 
00736    root_height = GetSystemMetrics(SM_CYSCREEN);
00737 
00738    /* Create the app. window */
00739    m_hWnd = CreateWindow("Gadgeteer Event Window", mInstName.c_str(),
00740                          WS_OVERLAPPEDWINDOW, mX,
00741                          root_height - mY - mHeight, mWidth, mHeight,
00742                          (HWND) NULL, NULL, m_hInst, (LPSTR) NULL);
00743    ShowWindow(m_hWnd,SW_SHOW);
00744    UpdateWindow(m_hWnd);
00745 
00746    // Attach a pointer to the device for use from the WNDPROC
00747    SetWindowLong(m_hWnd, GWL_USERDATA, (LPARAM)this);
00748 
00749    DWORD dwErr = GetLastError();
00750    if ( !m_hWnd )
00751    {
00752       return;
00753    }
00754 
00755 } /*CreateWindow*/

void gadget::EventWindowWin32::updKeys const MSG &    message [protected]
 

Definition at line 299 of file EventWindowWin32.cpp.

References addKeyEvent, addMouseButtonEvent, addMouseMoveEvent, gadgetDBG_INPUT_MGR, GET_X_LPARAM, GET_Y_LPARAM, Lock_KeyDown, Lock_LockKey, lockMouse, m_hWnd, mHeight, gadget::Input::mInstName, mKeys, mLockState, mLockStoredKey, mLockToggleKey, mPrevX, mPrevY, mRealkeys, mWidth, processEvent, Unlocked, unlockMouse, and VKKeyToKey.

Referenced by handleEvents.

00300 {
00301    vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_HVERB_LVL)
00302       << mInstName << ": KeyWin32::updKeys: Processing keys.\n"
00303       << vprDEBUG_FLUSH;
00304 
00305    gadget::Keys key;
00306 
00307    switch ( message.message )
00308    {
00309       case WM_ACTIVATE:
00310          // if was activated, and not minimized
00311          if ( (WA_ACTIVE == LOWORD(message.wParam) ||
00312                WA_CLICKACTIVE == LOWORD(message.wParam)) &&
00313               0 == HIWORD(message.wParam) )
00314          {
00315             // and was previously locked...
00316             if ( Unlocked != mLockState )
00317             {
00318                this->lockMouse();
00319             }
00320          }
00321          // if was deactivated and minimized
00322          // otherwise let CAPTURECHANGED handle the lose capture case
00323          else if ( WA_INACTIVE == LOWORD(message.wParam) &&
00324                    0 != HIWORD(message.wParam) )
00325          {
00326             // and was locked...
00327             if ( Unlocked != mLockState )
00328             {
00329                // we will leave mLockState in the locked state so ACTIVATE puts it back.
00330                this->unlockMouse();
00331             }
00332          }
00333          break;
00334 
00335          // sent to the window that is losing the mouse capture
00336       case WM_CAPTURECHANGED:
00337          // if locked, unlock it
00338          if ( Unlocked != mLockState )
00339          {
00340             // we will leave mLockState in the locked state so ACTIVATE puts it back.
00341             this->unlockMouse();
00342          }
00343          break;
00344 
00345          // keys and buttons
00346          // When we hit a key (or button), then set the mKey and mRealkey
00347          // When release, only set real so that we don't lose a press of the
00348          // button then when the updateData happens, the framekeys will be set to
00349          // non-pressed from real_keys
00350 
00351          // press
00352       case WM_SYSKEYDOWN:  //Need WM_SYSKEYDOWN to capture ALT key
00353       case WM_KEYDOWN:
00354          {
00355             // collect data about the keypress.
00356             key = this->VKKeyToKey(message.wParam);
00357 
00358             addKeyEvent(key, gadget::KeyPressEvent, message);
00359 
00360             // get the repeat count in case the key was pressed
00361             // multiple times since last we got this message
00362             int repeat_count = message.lParam & 0x0000ffff;
00363 
00364             // check if the key was down already
00365             // this indicates key repeat, which we [may] want to ignore.
00366             bool was_down = (message.lParam & 0x40000000) == 0x40000000;
00367             if ( was_down )
00368             {
00369                break;
00370             }
00371 
00372             // process the keypress.
00373             mKeys[key] += repeat_count;
00374             mRealkeys[key] += 1;
00375 
00376             // Check for Escape from bad state
00377             // this provides a sort of failsafe to
00378             // get out of the locked state...
00379             // @todo this is sort of hard coded, do we want it this way?
00380             if ( key == gadget::KEY_ESC )
00381             {
00382                if ( mLockState != Unlocked )
00383                {
00384                   mLockState = Unlocked;
00385                   this->unlockMouse();
00386                }
00387             }
00388             else if ( mLockState == Unlocked )
00389             {
00390                if ( (key != mLockToggleKey) &&
00391                     ((gadget::KEY_ALT == key) || (gadget::KEY_CTRL == key) || (gadget::KEY_SHIFT == key)) )
00392                {
00393                   mLockState = Lock_KeyDown;       // Switch state
00394                   mLockStoredKey = key;         // Store the VJ key that is down
00395                   this->lockMouse();
00396                }
00397                else if ( key == mLockToggleKey )
00398                {
00399                   mLockState = Lock_LockKey;
00400                   this->lockMouse();
00401                }
00402             }
00403             // Just switch the current locking state
00404             else if ( (mLockState == Lock_KeyDown) && (key == mLockToggleKey) )
00405             {
00406                mLockState = Lock_LockKey;
00407             }
00408             else if ( (mLockState == Lock_LockKey) && (key == mLockToggleKey) )
00409             {
00410                mLockState = Unlocked;
00411                this->unlockMouse();
00412             }
00413          }
00414          break;
00415 
00416          // release
00417       case WM_SYSKEYUP:  //Need WM_SYSKEYUP to capture ALT key
00418       case WM_KEYUP:
00419          key = VKKeyToKey(message.wParam);
00420          mRealkeys[key] = 0;
00421          vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_HVERB_LVL)
00422             << mInstName << ": WM_KEYUP: " << key << std::endl
00423             << vprDEBUG_FLUSH;
00424 
00425          addKeyEvent(key, gadget::KeyReleaseEvent, message);
00426 
00427          // -- Update lock state -- //
00428          // lock_keyDown[key==storedKey]/unlockMouse -> unlocked
00429          if ( (mLockState == Lock_KeyDown) && (key == mLockStoredKey) )
00430          {
00431             mLockState = Unlocked;
00432             this->unlockMouse();
00433          }
00434          break;
00435 
00436          // press...
00437       case WM_LBUTTONDOWN:
00438          mRealkeys[gadget::MBUTTON1] = 1;
00439          mKeys[gadget::MBUTTON1] += 1;
00440          addMouseButtonEvent(gadget::MBUTTON1, gadget::MouseButtonPressEvent,
00441                              message);
00442          vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_HVERB_LVL)
00443             << "LeftButtonDown\n" << vprDEBUG_FLUSH;
00444          break;
00445       case WM_MBUTTONDOWN:
00446          mRealkeys[gadget::MBUTTON2] = 1;
00447          mKeys[gadget::MBUTTON2] += 1;
00448          addMouseButtonEvent(gadget::MBUTTON2, gadget::MouseButtonPressEvent,
00449                              message);
00450          vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_HVERB_LVL)
00451             << "MiddleButtonDown\n" << vprDEBUG_FLUSH;
00452          break;
00453       case WM_RBUTTONDOWN:
00454          mRealkeys[gadget::MBUTTON3] = 1;
00455          mKeys[gadget::MBUTTON3] += 1;
00456          addMouseButtonEvent(gadget::MBUTTON3, gadget::MouseButtonPressEvent,
00457                              message);
00458          vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_HVERB_LVL)
00459             << "RightButtonDown\n" << vprDEBUG_FLUSH;
00460          break;
00461 
00462          // release...
00463       case WM_LBUTTONUP:
00464          mRealkeys[gadget::MBUTTON1] = 0;
00465          addMouseButtonEvent(gadget::MBUTTON1,
00466                              gadget::MouseButtonReleaseEvent, message);
00467          vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_HVERB_LVL)
00468             << "LeftButtonUp\n" << vprDEBUG_FLUSH;
00469          break;
00470       case WM_MBUTTONUP:
00471          mRealkeys[gadget::MBUTTON2] = 0;
00472          addMouseButtonEvent(gadget::MBUTTON2,
00473                              gadget::MouseButtonReleaseEvent, message);
00474          vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_HVERB_LVL)
00475             << "MiddleButtonUp\n" << vprDEBUG_FLUSH;
00476          break;
00477       case WM_RBUTTONUP:
00478          mRealkeys[gadget::MBUTTON3] = 0;
00479          addMouseButtonEvent(gadget::MBUTTON3,
00480                              gadget::MouseButtonReleaseEvent, message);
00481          vprDEBUG(gadgetDBG_INPUT_MGR, vprDBG_HVERB_LVL)
00482             << "RightButtonUp\n" << vprDEBUG_FLUSH;
00483          break;
00484 
00485          // mouse movement
00486       case WM_MOUSEMOVE:
00487          {
00488             addMouseMoveEvent(message);
00489 
00490             int win_center_x(mWidth / 2), win_center_y(mHeight / 2);
00491 
00492             int cur_x, cur_y, dx, dy;
00493 
00494             // Determine how far the mouse pointer moved since the last event.
00495             // x & y are relative to the x window
00496             cur_x = GET_X_LPARAM(message.lParam);
00497             cur_y = GET_Y_LPARAM(message.lParam);
00498 
00499             vprDEBUG(vprDBG_ALL,vprDBG_HVERB_LVL) << "MotionNotify: x:"
00500                << std::setw(6) << cur_x
00501                << "  y:" << std::setw(6) << cur_y << std::endl
00502                << vprDEBUG_FLUSH;
00503 
00504             if ( mLockState == Unlocked )
00505             {
00506                dx = cur_x - mPrevX;
00507                dy = cur_y - mPrevY;
00508 
00509                mPrevX = cur_x;
00510                mPrevY = cur_y;
00511             }
00512             else
00513             {
00514                dx = cur_x - win_center_x; // Base delta off of center of window
00515                dy = cur_y - win_center_y;
00516                mPrevX = win_center_x;    // Must do this so if state changes, we have accurate dx,dy next time
00517                mPrevY = win_center_y;
00518 
00519                // Warp back to center, IF we are not there already
00520                // This prevents us from sending an event based on our XWarp event
00521                if ( (dx != 0) || (dy != 0) )
00522                {
00523                   vprDEBUG(vprDBG_ALL,vprDBG_HVERB_LVL) << "CORRECTING: x:"
00524                      << std::setw(6) << dx << "  y:"
00525                      << std::setw(6) << dy
00526                      << std::endl << vprDEBUG_FLUSH;
00527 
00528                   // convert windows coords to screen coords.
00529                   POINT pt;
00530                   pt.x = win_center_x;
00531                   pt.y = win_center_y;
00532                   ::ClientToScreen(m_hWnd, &pt);
00533                   ::SetCursorPos(pt.x, pt.y);
00534                }
00535             }
00536 
00537             // Update mKeys based on key pressed and store in the key array
00538             if ( dx > 0 )
00539             {
00540                mKeys[gadget::MOUSE_POSX] += dx;     // Positive movement in the x direction.
00541             }
00542             else
00543             {
00544                mKeys[gadget::MOUSE_NEGX] += -dx;    // Negative movement in the x direction.
00545             }
00546 
00547             if ( dy > 0 )
00548             {
00549                mKeys[gadget::MOUSE_POSY] += dy;     // Positive movement in the y direction.
00550             }
00551             else
00552             {
00553                mKeys[gadget::MOUSE_NEGY] += -dy;    // Negative movement in the y direction.
00554             }
00555          }
00556          break;
00557    } // end of switch...
00558 
00559    // Let any other event watchers process their events
00560    this->processEvent(message.message, message.wParam, message.lParam);
00561 }

void gadget::EventWindowWin32::handleEvents   [protected]
 

Handles any events in the system.

Copies mKeys to mCurKeys.

Definition at line 156 of file EventWindowWin32.cpp.

References m_hWnd, mKeysLock, and updKeys.

Referenced by sample.

00157 {
00158    MSG msg;
00159    bool have_events_to_check = false;
00160    if ( mWeOwnTheWindow )
00161    {
00162       // block until message received.
00163       int retval = ::GetMessage(&msg, m_hWnd, 0, 0);
00164       vprASSERT(retval != -1 && "invalid m_hWnd window handle or invalid lpMsg pointer");
00165       if ( retval == -1 ) return; // for opt mode...
00166       have_events_to_check = true;
00167    }
00168    // check for event, if none, then exit.
00169    else if ( ::PeekMessage(&msg, m_hWnd, 0, 0, PM_REMOVE) )
00170    {
00171       have_events_to_check = true;
00172    }
00173    else
00174    {
00175       have_events_to_check = false;
00176       return; // don't wait on the lock since there is nothing
00177               // afterwards that will be called when this is false.
00178    }
00179 
00180 // GUARD mKeys for duration of loop
00181 // Doing it here gives makes sure that we process all events and don't get only part of them for an update
00182 // In order to copy data over to the mCurKeys array
00183 // Lock access to the mKeys array for the duration of this function
00184 vpr::Guard<vpr::Mutex> guard(mKeysLock);
00185 
00186    while ( have_events_to_check )
00187    {
00188       // Since we have no accelerators, no need to call
00189       // TranslateAccelerator here.
00190       ::TranslateMessage(&msg);
00191 
00192       // do our own special handling of kb/mouse...
00193       this->updKeys(msg);
00194 
00195       // send the message to the registered event handler
00196       ::DispatchMessage(&msg);
00197 
00198       // see if there is more messages immediately waiting
00199       // (don't block), process them all at once...
00200       int retval = ::PeekMessage(&msg, m_hWnd, 0, 0, PM_REMOVE);
00201       if ( retval != 0 ) // messages != 0, nomessages == 0
00202       {
00203          have_events_to_check = true;
00204       }
00205       else
00206       {
00207          have_events_to_check = false;
00208       }
00209 
00210       // user-specified sleep time.
00211       //vpr::System::usleep( mSleepTimeMS * 1000 );
00212    }
00213 }

int gadget::EventWindowWin32::onlyModifier int    [protected]
 

Definition at line 251 of file EventWindowWin32.cpp.

References gadget::EventWindow::mCurKeys.

00252 {
00253    switch ( mod )
00254    {
00255       case gadget::KEY_NONE:
00256          return(!mCurKeys[gadget::KEY_SHIFT] && !mCurKeys[gadget::KEY_CTRL] && !mCurKeys[gadget::KEY_ALT]);
00257       case gadget::KEY_SHIFT:
00258          return(mCurKeys[gadget::KEY_SHIFT] && !mCurKeys[gadget::KEY_CTRL] && !mCurKeys[gadget::KEY_ALT]);
00259       case gadget::KEY_CTRL:
00260          return(!mCurKeys[gadget::KEY_SHIFT] && mCurKeys[gadget::KEY_CTRL] && !mCurKeys[gadget::KEY_ALT]);
00261       case gadget::KEY_ALT:
00262          return(!mCurKeys[gadget::KEY_SHIFT] && !mCurKeys[gadget::KEY_CTRL] && mCurKeys[gadget::KEY_ALT]);
00263       default:
00264          vprASSERT(false);
00265          return 0;
00266    }
00267 }

gadget::Keys gadget::EventWindowWin32::VKKeyToKey int    vkKey [protected]
 

Definition at line 577 of file EventWindowWin32.cpp.

Referenced by updKeys.

00578 {
00579    switch ( vkKey )
00580    {
00581       case VK_UP      : return gadget::KEY_UP;
00582       case VK_DOWN    : return gadget::KEY_DOWN;
00583       case VK_LEFT    : return gadget::KEY_LEFT;
00584       case VK_RIGHT   : return gadget::KEY_RIGHT;
00585       case VK_CONTROL  : return gadget::KEY_CTRL;
00586       case VK_SHIFT   : return gadget::KEY_SHIFT;
00587       case VK_MENU     : return gadget::KEY_ALT;
00588       case /*VK_1*/0x31  : return gadget::KEY_1;
00589       case VK_NUMPAD1   : return gadget::KEY_1;
00590       case /*VK_2*/0x32  : return gadget::KEY_2;
00591       case VK_NUMPAD2   : return gadget::KEY_2;
00592       case /*VK_3*/0x33 : return gadget::KEY_3;
00593       case VK_NUMPAD3   : return gadget::KEY_3;
00594       case /*VK_4*/0x34  : return gadget::KEY_4;
00595       case VK_NUMPAD4   : return gadget::KEY_4;
00596       case /*VK_5*/0x35 : return gadget::KEY_5;
00597       case VK_NUMPAD5   : return gadget::KEY_5;
00598       case /*VK_6*/0x36  : return gadget::KEY_6;
00599       case VK_NUMPAD6   : return gadget::KEY_6;
00600       case /*VK_7*/0x37  : return gadget::KEY_7;
00601       case VK_NUMPAD7   : return gadget::KEY_7;
00602       case /*VK_8*/0x38  : return gadget::KEY_8;
00603       case VK_NUMPAD8   : return gadget::KEY_8;
00604       case /*VK_9*/0x39  : return gadget::KEY_9;
00605       case VK_NUMPAD9   : return gadget::KEY_9;
00606       case /*VK_0*/0x30  : return gadget::KEY_0;
00607       case VK_NUMPAD0   : return gadget::KEY_0;
00608       case /*VK_A*/0x41   : return gadget::KEY_A;
00609       case /*VK_B*/0x42   : return gadget::KEY_B;
00610       case /*VK_C*/0x43   : return gadget::KEY_C;
00611       case /*VK_D*/0x44   : return gadget::KEY_D;
00612       case /*VK_E*/0x45   : return gadget::KEY_E;
00613       case /*VK_F*/0x46   : return gadget::KEY_F;
00614       case /*VK_G*/0x47   : return gadget::KEY_G;
00615       case /*VK_H*/0x48   : return gadget::KEY_H;
00616       case /*VK_I*/0x49   : return gadget::KEY_I;
00617       case /*VK_J*/0x4a   : return gadget::KEY_J;
00618       case /*VK_K*/0x4b   : return gadget::KEY_K;
00619       case /*VK_L*/0x4c   : return gadget::KEY_L;
00620       case /*VK_M*/0x4d   : return gadget::KEY_M;
00621       case /*VK_N*/0x4e   : return gadget::KEY_N;
00622       case /*VK_O*/0x4f   : return gadget::KEY_O;
00623       case /*VK_P*/0x50   : return gadget::KEY_P;
00624       case /*VK_Q*/0x51   : return gadget::KEY_Q;
00625       case /*VK_R*/0x52   : return gadget::KEY_R;
00626       case /*VK_S*/0x53   : return gadget::KEY_S;
00627       case /*VK_T*/0x54   : return gadget::KEY_T;
00628       case /*VK_U*/0x55   : return gadget::KEY_U;
00629       case /*VK_V*/0x56   : return gadget::KEY_V;
00630       case /*VK_W*/0x57   : return gadget::KEY_W;
00631       case /*VK_X*/0x58   : return gadget::KEY_X;
00632       case /*VK_Y*/0x59   : return gadget::KEY_Y;
00633       case /*VK_Z*/0x5a   : return gadget::KEY_Z;
00634 
00635       case VK_ESCAPE  : return gadget::KEY_ESC;
00636       case VK_TAB     : return gadget::KEY_TAB;
00637 //      case VK_BACKTAB : return gadget::KEY_BACKTAB;
00638       case VK_BACK    : return gadget::KEY_BACKSPACE;
00639       case VK_RETURN  : return gadget::KEY_RETURN;
00640       case VK_INSERT  : return gadget::KEY_INSERT;
00641       case VK_DELETE  : return gadget::KEY_DELETE;
00642       case VK_PAUSE   : return gadget::KEY_PAUSE;
00643 //      case VK_???     : return gadget::KEY_SYSREQ;
00644       case VK_HOME    : return gadget::KEY_HOME;
00645       case VK_END     : return gadget::KEY_END;
00646       case VK_PRIOR   : return gadget::KEY_PRIOR;
00647       case VK_NEXT    : return gadget::KEY_NEXT;
00648       case VK_CAPITAL : return gadget::KEY_CAPS_LOCK;
00649       case VK_NUMLOCK : return gadget::KEY_NUM_LOCK;
00650       case VK_SCROLL  : return gadget::KEY_SCROLL_LOCK;
00651 
00652       case VK_F1  : return gadget::KEY_F1;
00653       case VK_F2  : return gadget::KEY_F2;
00654       case VK_F3  : return gadget::KEY_F3;
00655       case VK_F4  : return gadget::KEY_F4;
00656       case VK_F5  : return gadget::KEY_F5;
00657       case VK_F6  : return gadget::KEY_F6;
00658       case VK_F7  : return gadget::KEY_F7;
00659       case VK_F8  : return gadget::KEY_F8;
00660       case VK_F9  : return gadget::KEY_F9;
00661       case VK_F10 : return gadget::KEY_F10;
00662       case VK_F11 : return gadget::KEY_F11;
00663       case VK_F12 : return gadget::KEY_F12;
00664       case VK_F13 : return gadget::KEY_F13;
00665       case VK_F14 : return gadget::KEY_F14;
00666       case VK_F15 : return gadget::KEY_F15;
00667       case VK_F16 : return gadget::KEY_F16;
00668       case VK_F17 : return gadget::KEY_F17;
00669       case VK_F18 : return gadget::KEY_F18;
00670       case VK_F19 : return gadget::KEY_F19;
00671       case VK_F20 : return gadget::KEY_F20;
00672       case VK_F21 : return gadget::KEY_F21;
00673       case VK_F22 : return gadget::KEY_F22;
00674       case VK_F23 : return gadget::KEY_F23;
00675       case VK_F24 : return gadget::KEY_F24;
00676 
00677       case VK_HELP  : return gadget::KEY_HELP;
00678       case VK_SPACE : return gadget::KEY_SPACE;
00679 
00680       default: return gadget::KEY_UNKNOWN;
00681    }
00682 
00683 }

char* gadget::EventWindowWin32::checkArgs char *    look_for [protected]
 

BOOL gadget::EventWindowWin32::MenuInit HINSTANCE    hInstance [protected]
 

Definition at line 757 of file EventWindowWin32.cpp.

References MenuWndProc.

Referenced by createWindowWin32.

00758 {
00759    HANDLE   hMemory;
00760    PWNDCLASS pWndClass;
00761    BOOL     bSuccess;
00762 
00763    /* Initialize the menu window class */
00764    hMemory   = LocalAlloc(LPTR, sizeof(WNDCLASS));
00765    if ( !hMemory )
00766    {
00767       MessageBox(NULL, ("<MenuInit> Not enough memory."), NULL, MB_OK | MB_ICONHAND);
00768       return(FALSE);
00769    }
00770 
00771    pWndClass = (PWNDCLASS) LocalLock(hMemory);
00772 
00773    pWndClass->style         = 0;
00774    pWndClass->lpfnWndProc   = (WNDPROC) MenuWndProc;
00775    pWndClass->hInstance     = hInstance;
00776 //   pyrate_x = (HICON)LoadIcon(hInstance, _T("prof"));
00777    pWndClass->hIcon         = (HICON) LoadIcon(hInstance, TEXT("Juggler"));
00778    pWndClass->hCursor       = (HCURSOR) LoadCursor(NULL, IDC_ARROW);
00779    pWndClass->hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
00780    pWndClass->lpszMenuName  = ("MenuMenu"),
00781    pWndClass->lpszClassName = ("Gadgeteer Event Window");
00782 
00783    bSuccess = RegisterClass(pWndClass);
00784    LocalUnlock(hMemory);
00785    LocalFree(hMemory);
00786 
00787    return bSuccess;
00788 }


Friends And Related Function Documentation

LONG APIENTRY MenuWndProc HWND    hWnd,
UINT    message,
UINT    wParam,
LONG    lParam
[friend]
 

Definition at line 699 of file EventWindowWin32.cpp.

Referenced by MenuInit.

00700 {
00701    switch ( message )
00702    {
00703       case WM_SYSCOMMAND:
00704          return DefWindowProc(hWnd, message, wParam, lParam);
00705 
00706 //      case WM_COMMAND:
00707 //         break;
00708 
00709       case WM_SIZE:
00710          if ( lParam )
00711          {
00712             InvalidateRect(hWnd, NULL, TRUE);
00713          }
00714          break;
00715 
00716       case WM_DESTROY:
00717          PostQuitMessage(0);
00718          break;
00719 
00720       default:
00721          return DefWindowProc(hWnd, message, wParam, lParam);
00722    }
00723    return 0;
00724 }


Member Data Documentation

HINSTANCE gadget::EventWindowWin32::m_hInst [protected]
 

Definition at line 159 of file EventWindowWin32.h.

Referenced by createWindowWin32.

HWND gadget::EventWindowWin32::m_hWnd [protected]
 

Definition at line 160 of file EventWindowWin32.h.

Referenced by createWindowWin32, handleEvents, lockMouse, stopSampling, and updKeys.

bool gadget::EventWindowWin32::mWeOwnTheWindow [protected]
 

True if this class owns the window (is reposible for opening, closing, and event processing).

Definition at line 184 of file EventWindowWin32.h.

Referenced by config.

int gadget::EventWindowWin32::mScreen [protected]
 

Definition at line 185 of file EventWindowWin32.h.

int gadget::EventWindowWin32::mX [protected]
 

Definition at line 185 of file EventWindowWin32.h.

Referenced by config, and createWindowWin32.

int gadget::EventWindowWin32::mY [protected]
 

screen id, x-origin, y-origin.

Definition at line 185 of file EventWindowWin32.h.

Referenced by config, and createWindowWin32.

unsigned int gadget::EventWindowWin32::mWidth [protected]
 

Definition at line 186 of file EventWindowWin32.h.

Referenced by config, createWindowWin32, lockMouse, and updKeys.

unsigned int gadget::EventWindowWin32::mHeight [protected]
 

Definition at line 186 of file EventWindowWin32.h.

Referenced by config, createWindowWin32, lockMouse, and updKeys.

int gadget::EventWindowWin32::mKeys[gadget::LAST_KEY] [protected]
 

(0,*): The num key presses during an UpdateData (ie.

How many keypress events).

Definition at line 191 of file EventWindowWin32.h.

Referenced by config, updateData, and updKeys.

int gadget::EventWindowWin32::mRealkeys[gadget::LAST_KEY] [protected]
 

(0,1): The real keyboard state, all events processed (ie.

what is the key now).

Definition at line 192 of file EventWindowWin32.h.

Referenced by config, updateData, and updKeys.

vpr::Mutex gadget::EventWindowWin32::mKeysLock [protected]
 

Must hold this lock when accessing mKeys.

Definition at line 194 of file EventWindowWin32.h.

Referenced by handleEvents, and updateData.

bool gadget::EventWindowWin32::mExitFlag [protected]
 

Should we exit?

Definition at line 195 of file EventWindowWin32.h.

Referenced by controlLoop, startSampling, and stopSampling.

lockState gadget::EventWindowWin32::mLockState [protected]
 

The current state of locking.

Definition at line 197 of file EventWindowWin32.h.

Referenced by config, controlLoop, and updKeys.

int gadget::EventWindowWin32::mLockStoredKey [protected]
 

The key that was pressed down.

Definition at line 198 of file EventWindowWin32.h.

Referenced by updKeys.

int gadget::EventWindowWin32::mLockToggleKey [protected]
 

The key that toggles the locking.

Definition at line 199 of file EventWindowWi