source: golgotha/src/i4/device/svgalib/keyboard.hh @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 14 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 2.3 KB
Line 
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
18void key_handler(int scancode, int press);
19
20class 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
83extern svgalib_keyboard_class svgalib_keyboard_instance;
84
85#endif
Note: See TracBrowser for help on using the repository browser.