1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*
24cc -o test HIDParamTest.c -lIOKit
25*/
26
27#include <IOKit/IOKitLib.h>
28#include <IOKit/hidsystem/IOHIDShared.h>
29#include <assert.h>
30
31mach_port_t	masterPort;
32
33io_connect_t OpenEventDriver( void )
34{
35	register kern_return_t	kr;
36	mach_port_t		ev, service, iter;
37
38	assert( KERN_SUCCESS == (
39	kr = IOServiceGetMatchingServices( masterPort,
40			 IOServiceMatching( kIOHIDSystemClass ), &iter)
41	));
42
43	assert(
44	service = IOIteratorNext( iter )
45	);
46
47	assert( KERN_SUCCESS == (
48        kr = IOServiceOpen( service,
49			mach_task_self(),
50			kIOHIDParamConnectType,
51			&ev)
52	));
53
54	IOObjectRelease( service );
55	IOObjectRelease( iter );
56
57	return( ev );
58}
59
60
61void TestParams( io_connect_t ev )
62{
63	kern_return_t	kr;
64	NXEventData	event;
65	IOGPoint       	loc;
66	char *		s = "hello ";
67	char		c;
68
69	loc.x = 200;
70	loc.y = 200;
71
72	assert( KERN_SUCCESS == (
73	kr = IOHIDSetMouseLocation( ev, 200, 200 )
74	));
75
76	while( (c = *(s++))) {
77            event.key.repeat = FALSE;
78            event.key.keyCode = 0;
79            event.key.charSet = NX_ASCIISET;
80            event.key.charCode = c;
81            event.key.origCharSet = event.key.charSet;
82            event.key.origCharCode = event.key.charCode;
83
84            assert( KERN_SUCCESS == (
85            kr = IOHIDPostEvent ( ev, NX_KEYDOWN, loc, &event,
86				  FALSE, 0, FALSE )
87            ));
88            assert( KERN_SUCCESS == (
89            kr = IOHIDPostEvent ( ev, NX_KEYUP, loc, &event,
90				  FALSE, 0, FALSE )
91            ));
92	}
93}
94
95int
96main(int argc, char **argv)
97{
98	kern_return_t		kr;
99
100	assert( KERN_SUCCESS == (
101	kr = IOMasterPort(   bootstrap_port,
102			     &masterPort)
103	));
104	TestParams( OpenEventDriver());
105
106	return( 0 );
107}
108