1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #ifndef __SVGALIB_KEYBOARD_HPP_
|
---|
10 | #define __SVGALIB_KEYBOARD_HPP_
|
---|
11 |
|
---|
12 | #include "device/event.hh"
|
---|
13 | #include "device/device.hh"
|
---|
14 | #include "device/keys.hh"
|
---|
15 | #include <vgakeyboard.h>
|
---|
16 | #include <stdlib.h>
|
---|
17 |
|
---|
18 | void key_handler(int scancode, int press);
|
---|
19 |
|
---|
20 | class svgalib_keyboard_class : public i4_device_class
|
---|
21 | {
|
---|
22 | int inited;
|
---|
23 | public :
|
---|
24 | svgalib_keyboard_class() { inited=0; }
|
---|
25 | char *name() { return "SVGALIB keyboard"; }
|
---|
26 | void send_key(int key, int press)
|
---|
27 | {
|
---|
28 | if (press)
|
---|
29 | {
|
---|
30 | i4_key_press_event_class ev(key);
|
---|
31 | send_event_to_agents(&ev,FLAG_KEY_PRESS);
|
---|
32 | }
|
---|
33 | else
|
---|
34 | {
|
---|
35 | i4_key_release_event_class ev(key);
|
---|
36 | send_event_to_agents(&ev,FLAG_KEY_RELEASE);
|
---|
37 | }
|
---|
38 | }
|
---|
39 |
|
---|
40 | // Implement these functions for each device
|
---|
41 | virtual i4_bool process_events() // returns true if an event was dispatched
|
---|
42 | {
|
---|
43 | keyboard_update();
|
---|
44 | }
|
---|
45 |
|
---|
46 | virtual w32 request_device(i4_event_handler_class *for_who, w32 event_types)
|
---|
47 | {
|
---|
48 | if (!inited)
|
---|
49 | if (keyboard_init()==0)
|
---|
50 | {
|
---|
51 | keyboard_seteventhandler(key_handler);
|
---|
52 | inited=1;
|
---|
53 | }
|
---|
54 |
|
---|
55 | if (inited)
|
---|
56 | {
|
---|
57 | if (event_types&i4_event::KEY_PRESS)
|
---|
58 | add_agent(for_who,i4_event::KEY_PRESS);
|
---|
59 | if (event_types&i4_event::KEY_RELEASE)
|
---|
60 | add_agent(for_who,i4_event::KEY_RELEASE);
|
---|
61 |
|
---|
62 | return (i4_event::KEY_PRESS|i4_event::KEY_RELEASE)&event_types;
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 |
|
---|
67 | virtual void release_device(i4_event_handler_class *for_who, w32 event_types)
|
---|
68 | {
|
---|
69 | if (event_types&i4_event::KEY_PRESS)
|
---|
70 | remove_agent(for_who,i4_event::KEY_PRESS);
|
---|
71 | if (event_types&i4_event::KEY_RELEASE)
|
---|
72 | remove_agent(for_who,i4_event::KEY_RELEASE);
|
---|
73 |
|
---|
74 | if (!agent_list && inited)
|
---|
75 | {
|
---|
76 | keyboard_setdefaulteventhandler();
|
---|
77 | keyboard_close();
|
---|
78 | inited=0;
|
---|
79 | }
|
---|
80 | }
|
---|
81 | } ;
|
---|
82 |
|
---|
83 | extern svgalib_keyboard_class svgalib_keyboard_instance;
|
---|
84 |
|
---|
85 | #endif
|
---|