blob: 195ac1f100ff0f7987f7f84e2785a6e1b99bb19c [file] [log] [blame]
hellner@google.com23a80652011-08-25 21:40:11 +00001/*
niklase@google.com470e71d2011-07-07 08:21:25 +00002 * 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.org59ccd5c2011-12-15 00:17:43 +000015 #include "event_win.h"
sjlee@webrtc.org414fa7f2012-09-11 17:25:46 +000016#elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
zakkhoyt@google.com59af6f12011-08-25 20:30:25 +000017 #include <ApplicationServices/ApplicationServices.h>
18 #include <pthread.h>
19 #include "event_posix.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000020#else
21 #include <pthread.h>
ajm@google.comb5c49ff2011-08-01 17:04:04 +000022 #include "event_posix.h"
niklase@google.com470e71d2011-07-07 08:21:25 +000023#endif
24
25namespace webrtc {
26EventWrapper* EventWrapper::Create()
27{
28#if defined(_WIN32)
29 return new EventWindows();
30#else
ajm@google.comb5c49ff2011-08-01 17:04:04 +000031 return EventPosix::Create();
niklase@google.com470e71d2011-07-07 08:21:25 +000032#endif
33}
34
35int 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.org414fa7f2012-09-11 17:25:46 +000052#elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
zakkhoyt@google.com59af6f12011-08-25 20:30:25 +000053 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.com470e71d2011-07-07 08:21:25 +000067#else
68 return -1;
69#endif
70}
71} // namespace webrtc