File: keyboard.cpp

package info (click to toggle)
libretro-bsnes-mercury 094%2Bgit20160126-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 9,636 kB
  • sloc: cpp: 109,056; ansic: 3,097; makefile: 638; xml: 11; sh: 1
file content (144 lines) | stat: -rw-r--r-- 5,521 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
namespace phoenix {

void pKeyboard::initialize() {
  auto append = [](Keyboard::Scancode scancode, unsigned keysym) {
    settings->keymap.insert(scancode, keysym);
  };

  append(Keyboard::Scancode::Escape, VK_ESCAPE);
  append(Keyboard::Scancode::F1, VK_F1);
  append(Keyboard::Scancode::F2, VK_F2);
  append(Keyboard::Scancode::F3, VK_F3);
  append(Keyboard::Scancode::F4, VK_F4);
  append(Keyboard::Scancode::F5, VK_F5);
  append(Keyboard::Scancode::F6, VK_F6);
  append(Keyboard::Scancode::F7, VK_F7);
  append(Keyboard::Scancode::F8, VK_F8);
  append(Keyboard::Scancode::F9, VK_F9);
  append(Keyboard::Scancode::F10, VK_F10);
  append(Keyboard::Scancode::F11, VK_F11);
  append(Keyboard::Scancode::F12, VK_F12);

  append(Keyboard::Scancode::PrintScreen, VK_SNAPSHOT);
  append(Keyboard::Scancode::ScrollLock, VK_SCROLL);
  append(Keyboard::Scancode::Pause, VK_PAUSE);

  append(Keyboard::Scancode::Insert, VK_INSERT);
  append(Keyboard::Scancode::Delete, VK_DELETE);
  append(Keyboard::Scancode::Home, VK_HOME);
  append(Keyboard::Scancode::End, VK_END);
  append(Keyboard::Scancode::PageUp, VK_PRIOR);
  append(Keyboard::Scancode::PageDown, VK_NEXT);

  append(Keyboard::Scancode::Up, VK_UP);
  append(Keyboard::Scancode::Down, VK_DOWN);
  append(Keyboard::Scancode::Left, VK_LEFT);
  append(Keyboard::Scancode::Right, VK_RIGHT);

  append(Keyboard::Scancode::Grave, VK_OEM_3);
  append(Keyboard::Scancode::Number1, '1');
  append(Keyboard::Scancode::Number2, '2');
  append(Keyboard::Scancode::Number3, '3');
  append(Keyboard::Scancode::Number4, '4');
  append(Keyboard::Scancode::Number5, '5');
  append(Keyboard::Scancode::Number6, '6');
  append(Keyboard::Scancode::Number7, '7');
  append(Keyboard::Scancode::Number8, '8');
  append(Keyboard::Scancode::Number9, '9');
  append(Keyboard::Scancode::Number0, '0');
  append(Keyboard::Scancode::Minus, VK_OEM_MINUS);
  append(Keyboard::Scancode::Equal, VK_OEM_PLUS);
  append(Keyboard::Scancode::Backspace, VK_BACK);

  append(Keyboard::Scancode::BracketLeft, VK_OEM_4);
  append(Keyboard::Scancode::BracketRight, VK_OEM_6);
  append(Keyboard::Scancode::Backslash, VK_OEM_5);
  append(Keyboard::Scancode::Semicolon, VK_OEM_1);
  append(Keyboard::Scancode::Apostrophe, VK_OEM_7);
  append(Keyboard::Scancode::Comma, VK_OEM_COMMA);
  append(Keyboard::Scancode::Period, VK_OEM_PERIOD);
  append(Keyboard::Scancode::Slash, VK_OEM_2);

  append(Keyboard::Scancode::Tab, VK_TAB);
  append(Keyboard::Scancode::CapsLock, VK_CAPITAL);
  append(Keyboard::Scancode::Return, VK_RETURN);
  append(Keyboard::Scancode::ShiftLeft, VK_LSHIFT);
  append(Keyboard::Scancode::ShiftRight, VK_RSHIFT);
  append(Keyboard::Scancode::ControlLeft, VK_LCONTROL);
  append(Keyboard::Scancode::ControlRight, VK_RCONTROL);
  append(Keyboard::Scancode::SuperLeft, VK_LWIN);
  append(Keyboard::Scancode::SuperRight, VK_RWIN);
  append(Keyboard::Scancode::AltLeft, VK_LMENU);
  append(Keyboard::Scancode::AltRight, VK_RMENU);
  append(Keyboard::Scancode::Space, VK_SPACE);
  append(Keyboard::Scancode::Menu, VK_APPS);

  append(Keyboard::Scancode::A, 'A');
  append(Keyboard::Scancode::B, 'B');
  append(Keyboard::Scancode::C, 'C');
  append(Keyboard::Scancode::D, 'D');
  append(Keyboard::Scancode::E, 'E');
  append(Keyboard::Scancode::F, 'F');
  append(Keyboard::Scancode::G, 'G');
  append(Keyboard::Scancode::H, 'H');
  append(Keyboard::Scancode::I, 'I');
  append(Keyboard::Scancode::J, 'J');
  append(Keyboard::Scancode::K, 'K');
  append(Keyboard::Scancode::L, 'L');
  append(Keyboard::Scancode::M, 'M');
  append(Keyboard::Scancode::N, 'N');
  append(Keyboard::Scancode::O, 'O');
  append(Keyboard::Scancode::P, 'P');
  append(Keyboard::Scancode::Q, 'Q');
  append(Keyboard::Scancode::R, 'R');
  append(Keyboard::Scancode::S, 'S');
  append(Keyboard::Scancode::T, 'T');
  append(Keyboard::Scancode::U, 'U');
  append(Keyboard::Scancode::V, 'V');
  append(Keyboard::Scancode::W, 'W');
  append(Keyboard::Scancode::X, 'X');
  append(Keyboard::Scancode::Y, 'Y');
  append(Keyboard::Scancode::Z, 'Z');

  append(Keyboard::Scancode::NumLock, VK_NUMLOCK);
  append(Keyboard::Scancode::Divide, VK_DIVIDE);
  append(Keyboard::Scancode::Multiply, VK_MULTIPLY);
  append(Keyboard::Scancode::Subtract, VK_SUBTRACT);
  append(Keyboard::Scancode::Add, VK_ADD);
//append(Keyboard::Scancode::Enter, ...);
  append(Keyboard::Scancode::Point, VK_DECIMAL);

  append(Keyboard::Scancode::Keypad1, VK_NUMPAD1);
  append(Keyboard::Scancode::Keypad2, VK_NUMPAD2);
  append(Keyboard::Scancode::Keypad3, VK_NUMPAD3);
  append(Keyboard::Scancode::Keypad4, VK_NUMPAD4);
  append(Keyboard::Scancode::Keypad5, VK_NUMPAD5);
  append(Keyboard::Scancode::Keypad6, VK_NUMPAD6);
  append(Keyboard::Scancode::Keypad7, VK_NUMPAD7);
  append(Keyboard::Scancode::Keypad8, VK_NUMPAD8);
  append(Keyboard::Scancode::Keypad9, VK_NUMPAD9);
  append(Keyboard::Scancode::Keypad0, VK_NUMPAD0);
}

bool pKeyboard::pressed(Keyboard::Scancode scancode) {
  if(auto result = settings->keymap.find(scancode)) {
    return GetAsyncKeyState(result()) & 0x8000;
  }
  return false;
}

vector<bool> pKeyboard::state() {
  vector<bool> output;
  output.resize((unsigned)Keyboard::Scancode::Limit);
  for(auto& n : output) n = false;

  for(auto node : settings->keymap) {
    if(GetAsyncKeyState(node.value) & 0x8000) {
      output[(unsigned)node.key] = true;
    }
  }

  return output;
}

}