Home | History | Annotate | Download | only in source
      1 /*
      2  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
      3  *
      4  *  Use of this source code is governed by a BSD-style license
      5  *  that can be found in the LICENSE file in the root of the source
      6  *  tree. An additional intellectual property rights grant can be found
      7  *  in the file PATENTS.  All contributing project authors may
      8  *  be found in the AUTHORS file in the root of the source tree.
      9  */
     10 
     11 #include "event_wrapper.h"
     12 
     13 #if defined(_WIN32)
     14     #include <windows.h>
     15     #include "event_win.h"
     16 #elif defined(WEBRTC_MAC_INTEL)
     17     #include <ApplicationServices/ApplicationServices.h>
     18     #include <pthread.h>
     19     #include "event_posix.h"
     20 #else
     21     #include <pthread.h>
     22     #include "event_posix.h"
     23 #endif
     24 
     25 namespace webrtc {
     26 EventWrapper* EventWrapper::Create()
     27 {
     28 #if defined(_WIN32)
     29     return new EventWindows();
     30 #else
     31     return EventPosix::Create();
     32 #endif
     33 }
     34 
     35 int EventWrapper::KeyPressed()
     36 {
     37 #if defined(_WIN32)
     38     int keyDown = 0;
     39     for(int key = 0x20; key < 0x90; key++)
     40     {
     41         short res = GetAsyncKeyState(key);
     42         keyDown |= res%2;  // Get the LSB
     43     }
     44     if(keyDown)
     45     {
     46         return 1;
     47     }
     48     else
     49     {
     50         return 0;
     51     }
     52 #elif defined(WEBRTC_MAC_INTEL)
     53     bool keyDown = false;
     54     // loop through all Mac virtual key constant values
     55     for(int keyIndex = 0; keyIndex <= 0x5C; keyIndex++)
     56     {
     57         keyDown |= CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, keyIndex);
     58     }
     59     if(keyDown)
     60     {
     61         return 1;
     62     }
     63     else
     64     {
     65         return 0;
     66     }
     67 #else
     68     return -1;
     69 #endif
     70 }
     71 } // namespace webrtc
     72