hellner@google.com | 23a8065 | 2011-08-25 21:40:11 +0000 | [diff] [blame] | 1 | /* |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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> |
andrew@webrtc.org | 59ccd5c | 2011-12-15 00:17:43 +0000 | [diff] [blame] | 15 | #include "event_win.h" |
sjlee@webrtc.org | 414fa7f | 2012-09-11 17:25:46 +0000 | [diff] [blame] | 16 | #elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
zakkhoyt@google.com | 59af6f1 | 2011-08-25 20:30:25 +0000 | [diff] [blame] | 17 | #include <ApplicationServices/ApplicationServices.h> |
| 18 | #include <pthread.h> |
| 19 | #include "event_posix.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | #else |
| 21 | #include <pthread.h> |
ajm@google.com | b5c49ff | 2011-08-01 17:04:04 +0000 | [diff] [blame] | 22 | #include "event_posix.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | #endif |
| 24 | |
| 25 | namespace webrtc { |
| 26 | EventWrapper* EventWrapper::Create() |
| 27 | { |
| 28 | #if defined(_WIN32) |
| 29 | return new EventWindows(); |
| 30 | #else |
ajm@google.com | b5c49ff | 2011-08-01 17:04:04 +0000 | [diff] [blame] | 31 | return EventPosix::Create(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | } |
sjlee@webrtc.org | 414fa7f | 2012-09-11 17:25:46 +0000 | [diff] [blame] | 52 | #elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
zakkhoyt@google.com | 59af6f1 | 2011-08-25 20:30:25 +0000 | [diff] [blame] | 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 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 67 | #else |
| 68 | return -1; |
| 69 | #endif |
| 70 | } |
| 71 | } // namespace webrtc |