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 | |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 11 | #include "webrtc/system_wrappers/interface/event_wrapper.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 12 | |
| 13 | #if defined(_WIN32) |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 14 | #include <windows.h> |
| 15 | #include "webrtc/system_wrappers/source/event_win.h" |
sjlee@webrtc.org | 414fa7f | 2012-09-11 17:25:46 +0000 | [diff] [blame] | 16 | #elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 17 | #include <ApplicationServices/ApplicationServices.h> |
| 18 | #include <pthread.h> |
| 19 | #include "webrtc/system_wrappers/source/event_posix.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | #else |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 21 | #include <pthread.h> |
| 22 | #include "webrtc/system_wrappers/source/event_posix.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 23 | #endif |
| 24 | |
| 25 | namespace webrtc { |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 26 | EventWrapper* EventWrapper::Create() { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 27 | #if defined(_WIN32) |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 28 | return new EventWindows(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 29 | #else |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 30 | return EventPosix::Create(); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 31 | #endif |
| 32 | } |
| 33 | |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 34 | int EventWrapper::KeyPressed() { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | #if defined(_WIN32) |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 36 | int key_down = 0; |
| 37 | for (int key = 0x20; key < 0x90; key++) { |
| 38 | short res = GetAsyncKeyState(key); |
| 39 | key_down |= res % 2; // Get the LSB |
| 40 | } |
| 41 | if (key_down) { |
| 42 | return 1; |
| 43 | } else { |
| 44 | return 0; |
| 45 | } |
sjlee@webrtc.org | 414fa7f | 2012-09-11 17:25:46 +0000 | [diff] [blame] | 46 | #elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 47 | bool key_down = false; |
| 48 | // loop through all Mac virtual key constant values |
| 49 | for (int key_index = 0; key_index <= 0x5C; key_index++) { |
| 50 | key_down |= CGEventSourceKeyState(kCGEventSourceStateHIDSystemState, |
| 51 | key_index); |
| 52 | } |
| 53 | if (key_down) { |
| 54 | return 1; |
| 55 | } else { |
| 56 | return 0; |
| 57 | } |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | #else |
phoglund@webrtc.org | 5bbe069 | 2012-12-10 10:44:37 +0000 | [diff] [blame] | 59 | return -1; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 60 | #endif |
| 61 | } |
| 62 | } // namespace webrtc |