1
/* $Id: tstDarwinKeyboard.cpp 28800 2010-04-27 08:22:32Z vboxsync $ */
3
* Common GUI Library - Testcase - Darwin Keyboard routines.
5
* @todo Move this up somewhere so that the two SDL GUIs can use parts of this code too (-HID crap).
9
* Copyright (C) 2006-2007 Oracle Corporation
11
* This file is part of VirtualBox Open Source Edition (OSE), as
12
* available from http://www.virtualbox.org. This file is free software;
13
* you can redistribute it and/or modify it under the terms of the GNU
14
* General Public License (GPL) as published by the Free Software
15
* Foundation, in version 2 as it comes in the "COPYING" file of the
16
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
17
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
21
/*******************************************************************************
23
*******************************************************************************/
24
#include <iprt/initterm.h>
25
#include <iprt/stream.h>
26
#include <iprt/string.h>
27
#include <iprt/time.h>
28
#include <iprt/assert.h>
30
#include "DarwinKeyboard.h"
32
int main(int argc, char **argv)
35
AssertReleaseRCReturn(rc, 1);
40
RTPrintf("tstDarwinKeyboard: Warmup...\n");
43
DarwinGrabKeyboard(true);
44
DarwinReleaseKeyboard();
47
DarwinGrabKeyboard(true);
48
DarwinReleaseKeyboard();
51
unsigned DarwinKeycodeToSet1Scancode(unsigned uKeyCode);
52
UInt32 DarwinAdjustModifierMask(UInt32 fModifiers);
53
unsigned DarwinModifierMaskToSet1Scancode(UInt32 fModifiers);
54
unsigned DarwinModifierMaskToDarwinKeycode(UInt32 fModifiers);
55
UInt32 DarwinKeyCodeToDarwinModifierMask(unsigned uKeyCode);
56
unsigned DarwinEventToSet1Scancode(EventRef Event, UInt32 *pfCurKeyModifiers);
57
void DarwinDisableGlobalHotKeys(bool fDisable);
61
* Grab and release the keyboard a lot of times and time it.
62
* We're looking both at performance and for memory and reference leaks here.
64
RTPrintf("tstDarwinKeyboard: Profiling Grab and Release");
65
RTStrmFlush(g_pStdOut);
66
const uint64_t u64Start = RTTimeNanoTS();
68
uint64_t u64Release = 0;
70
for (i = 0; i < 20; i++)
72
uint64_t u64 = RTTimeNanoTS();
73
DarwinGrabKeyboard(argc != 1);
74
u64Grab += RTTimeNanoTS() - u64;
77
DarwinReleaseKeyboard();
78
u64Release += RTTimeNanoTS() - u64;
83
RTStrmFlush(g_pStdOut);
86
const uint64_t u64Elapsed = RTTimeNanoTS() - u64Start;
88
"tstDarwinKeyboard: %u times in %RU64 ms - %RU64 ms per call\n",
89
i, u64Elapsed / 1000000, (u64Elapsed / i) / 1000000);
90
RTPrintf("tstDarwinKeyboard: DarwinGrabKeyboard: %RU64 ms total - %RU64 ms per call\n",
91
u64Grab / 1000000, (u64Grab / i) / 1000000);
92
RTPrintf("tstDarwinKeyboard: DarwinReleaseKeyboard: %RU64 ms total - %RU64 ms per call\n",
93
u64Release / 1000000, (u64Release / i) / 1000000);