vrpn
07.35
Virtual Reality Peripheral Network
Toggle main menu visibility
Loading...
Searching...
No Matches
vrpn_Keyboard.C
Go to the documentation of this file.
1
#include <stdio.h>
// for fprintf, stderr
2
3
#include "
vrpn_Keyboard.h
"
4
#include "
vrpn_Shared.h
"
// for timeval, vrpn_gettimeofday
5
6
class
VRPN_API
vrpn_Connection
;
7
#ifdef _WIN32
8
#pragma comment (lib, "user32.lib")
9
#endif
10
11
vrpn_Keyboard::vrpn_Keyboard
(
const
char
* name,
vrpn_Connection
* c) :
12
vrpn_Button_Filter
(name, c)
13
{
14
int
i;
15
// Set the parameters in the parent classes
16
num_buttons
= 256;
17
18
for
( i = 0; i <
num_buttons
; i++) {
19
buttons
[i] =
lastbuttons
[i] = 0;
20
}
21
22
#ifndef _WIN32
23
fprintf(stderr,
"vrpn_Keyboard:: Not implement on this architecture\n"
);
24
#endif
25
}
26
27
vrpn_Keyboard::~vrpn_Keyboard
()
28
{
29
}
30
31
int
vrpn_Keyboard::get_report
(
void
)
32
{
33
struct
timeval time;
34
vrpn_gettimeofday
(&time, NULL);
// set timestamp of this event
35
timestamp
= time;
36
#ifdef _WIN32
37
int
i;
38
// Read one key state, which will read all of the events
39
// and make it possible to read the state of all the keys;
40
// We're ignoring the return for this particular key; it
41
// will be read again as part of the 256-key read below.
42
GetKeyState(1);
43
44
// Read all 256 keys from the keyboard, then translate the
45
// "virtual key" value from each into a scanline code and fill
46
// in the appropriate entry with each value.
47
BYTE virtual_keys[256];
48
if
(GetKeyboardState(virtual_keys) == 0) {
49
fprintf(stderr,
"vrpn_Keyboard::get_report(): Could not read keyboard state\n"
);
50
return
0;
51
}
52
53
// Clear all 256 key values, then fill in the ones that are
54
// nonzero. This is done because some of the keys from the
55
// keyboard (control and shift) map into the same scan code;
56
// if we just set all of the codes, then the right ones
57
// overwrite the left ones.
58
for
(i = 0; i < 256; i++) {
59
buttons
[i] = 0;
60
}
61
for
(i = 0; i < 256; i++) {
62
unsigned
scancode = MapVirtualKey(i, 0);
63
if
( (scancode != 0) && ((0x80 & virtual_keys[i]) != 0) ) {
64
buttons
[scancode] = 1;
65
}
66
}
67
#endif
68
report_changes
();
// Report updates to VRPN
69
return
0;
70
}
71
72
// This routine is called each time through the server's main loop. It will
73
// get a reading and also handle the server_mainloop requirement.
74
void
vrpn_Keyboard::mainloop
()
75
{
76
server_mainloop
();
77
get_report
();
78
}
vrpn_BaseClassUnique::server_mainloop
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
Definition
vrpn_BaseClass.C:604
vrpn_Button_Filter::report_changes
virtual void report_changes(void)
Definition
vrpn_Button.C:383
vrpn_Button_Filter::vrpn_Button_Filter
vrpn_Button_Filter(const char *, vrpn_Connection *c=NULL)
Definition
vrpn_Button.C:129
vrpn_Button::num_buttons
vrpn_int32 num_buttons
Definition
vrpn_Button.h:48
vrpn_Button::timestamp
struct timeval timestamp
Definition
vrpn_Button.h:49
vrpn_Button::lastbuttons
unsigned char lastbuttons[vrpn_BUTTON_MAX_BUTTONS]
Definition
vrpn_Button.h:46
vrpn_Button::buttons
unsigned char buttons[vrpn_BUTTON_MAX_BUTTONS]
Definition
vrpn_Button.h:45
vrpn_Connection
Generic connection class not specific to the transport mechanism.
Definition
vrpn_Connection.h:561
vrpn_Keyboard::~vrpn_Keyboard
~vrpn_Keyboard()
Definition
vrpn_Keyboard.C:27
vrpn_Keyboard::mainloop
virtual void mainloop()
Called once through each main loop iteration to handle updates.
Definition
vrpn_Keyboard.C:74
vrpn_Keyboard::get_report
virtual int get_report(void)
Read the current status. Return 1 if a report was found,.
Definition
vrpn_Keyboard.C:31
vrpn_Keyboard::vrpn_Keyboard
vrpn_Keyboard(const char *name, vrpn_Connection *c)
Definition
vrpn_Keyboard.C:11
VRPN_API
#define VRPN_API
Definition
vrpn_Configure.h:648
vrpn_Keyboard.h
vrpn_Connection
class VRPN_API vrpn_Connection
Definition
vrpn_Keyboard.h:15
vrpn_Shared.h
vrpn_gettimeofday
#define vrpn_gettimeofday
Definition
vrpn_Shared.h:99
vrpn_Keyboard.C
Generated by
1.17.0