mirror of
https://github.com/citra-emu/citra.git
synced 2025-04-19 06:10:08 +00:00
57 lines
1.5 KiB
C++
57 lines
1.5 KiB
C++
// Copyright 2016 Citra Emulator Project
|
|
// Licensed under GPLv2 or any later version
|
|
// Refer to the license.txt file included.
|
|
|
|
#include <SDL_keyboard.h>
|
|
|
|
#include "input_core/devices/Keyboard.h"
|
|
|
|
Keyboard::Keyboard() {
|
|
}
|
|
|
|
Keyboard::~Keyboard() {
|
|
}
|
|
|
|
bool Keyboard::InitDevice(int number, const std::map<std::string, std::vector<KeyMap::KeyTarget>>& keyMap) {
|
|
keyMapping = keyMap;
|
|
return true;
|
|
}
|
|
|
|
void Keyboard::ProcessInput() {
|
|
std::map<KeyboardKey, bool> keysPressedCopy;
|
|
{
|
|
std::lock_guard<std::mutex> lock(m);
|
|
keysPressedCopy = keysPressed;
|
|
}
|
|
for (const auto &ent1 : keyMapping) {
|
|
int scancode = std::stoul(ent1.first, nullptr, 16);
|
|
KeyboardKey proxy = KeyboardKey(0, scancode, "");
|
|
if (keysPressedCopy[proxy] == true && keysPressedLast[scancode] == false) {
|
|
for (const auto& key : ent1.second) {
|
|
KeyMap::PressKey(key, 1.0);
|
|
}
|
|
keysPressedLast[scancode] = true;
|
|
}
|
|
else if (keysPressedCopy[proxy] == false && keysPressedLast[scancode] == true) {
|
|
for (const auto& key : ent1.second) {
|
|
KeyMap::ReleaseKey(key);
|
|
}
|
|
keysPressedLast[scancode] = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
bool Keyboard::CloseDevice() {
|
|
return true;
|
|
}
|
|
|
|
void Keyboard::KeyPressed(KeyboardKey key) {
|
|
std::lock_guard<std::mutex> lock(m);
|
|
keysPressed[key] = true;
|
|
}
|
|
|
|
void Keyboard::KeyReleased(KeyboardKey key) {
|
|
std::lock_guard<std::mutex> lock(m);
|
|
keysPressed[key] = false;
|
|
}
|