87 lines
1.7 KiB
C++
87 lines
1.7 KiB
C++
#include "keyhandler.h"
|
|
#include <iostream>
|
|
#include <unistd.h>
|
|
|
|
KeyHandler::~KeyHandler()
|
|
{
|
|
}
|
|
|
|
void KeyHandler::Key(SpecialKey key, KeyModifiers mods)
|
|
{
|
|
WaitUntilNotPaused();
|
|
|
|
if (mods & KM_META_MASK) {
|
|
std::cout << "Meta+";
|
|
}
|
|
if (mods & KM_CTRL_MASK) {
|
|
std::cout << "Ctrl+";
|
|
}
|
|
if (mods & KM_ALT_MASK) {
|
|
std::cout << "Alt+";
|
|
}
|
|
if (mods & KM_SHIFT_MASK) {
|
|
std::cout << "Shift+";
|
|
}
|
|
|
|
switch (key) {
|
|
case SpecialKey::NONE:
|
|
break;
|
|
case SpecialKey::UP:
|
|
std::cout << "↑";
|
|
break;
|
|
case SpecialKey::DOWN:
|
|
std::cout << "↓";
|
|
break;
|
|
case SpecialKey::LEFT:
|
|
std::cout << "←";
|
|
break;
|
|
case SpecialKey::RIGHT:
|
|
std::cout << "→";
|
|
break;
|
|
case SpecialKey::HOME:
|
|
std::cout << "⇤";
|
|
break;
|
|
case SpecialKey::END:
|
|
std::cout << "⇥";
|
|
break;
|
|
case SpecialKey::RETURN:
|
|
std::cout << "↲\n";
|
|
break;
|
|
case SpecialKey::ESCAPE:
|
|
std::cout << "ESC\n";
|
|
break;
|
|
}
|
|
}
|
|
|
|
void KeyHandler::Key(char key, KeyModifiers mods)
|
|
{
|
|
WaitUntilNotPaused();
|
|
|
|
if (mods & KM_META_MASK) {
|
|
std::cout << "Meta+";
|
|
}
|
|
if (mods & KM_CTRL_MASK) {
|
|
std::cout << "Ctrl+";
|
|
}
|
|
if (mods & KM_ALT_MASK) {
|
|
std::cout << "Alt+";
|
|
}
|
|
if (mods & KM_SHIFT_MASK) {
|
|
std::cout << "Shift+";
|
|
}
|
|
std::cout << key;
|
|
}
|
|
|
|
void KeyHandler::TogglePaused()
|
|
{
|
|
m_paused = !m_paused;
|
|
std::cout << (m_paused ? "Paused\n" : "Resumed\n");
|
|
}
|
|
|
|
void KeyHandler::WaitUntilNotPaused()
|
|
{
|
|
while (m_paused) {
|
|
usleep(100000);
|
|
}
|
|
}
|