vrpn 07.35
Virtual Reality Peripheral Network
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
7#ifdef _WIN32
8#pragma comment (lib, "user32.lib")
9#endif
10
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
28{
29}
30
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.
75{
77 get_report();
78}
void server_mainloop(void)
Handles functions that all servers should provide in their mainloop() (ping/pong, for example) Should...
All button servers should derive from this class, which provides the ability to turn any of the butto...
Definition vrpn_Button.h:66
virtual void report_changes(void)
vrpn_int32 num_buttons
Definition vrpn_Button.h:48
struct timeval timestamp
Definition vrpn_Button.h:49
unsigned char lastbuttons[vrpn_BUTTON_MAX_BUTTONS]
Definition vrpn_Button.h:46
unsigned char buttons[vrpn_BUTTON_MAX_BUTTONS]
Definition vrpn_Button.h:45
Generic connection class not specific to the transport mechanism.
virtual void mainloop()
Called once through each main loop iteration to handle updates.
virtual int get_report(void)
Read the current status. Return 1 if a report was found,.
vrpn_Keyboard(const char *name, vrpn_Connection *c)
#define VRPN_API
#define vrpn_gettimeofday
Definition vrpn_Shared.h:99