mirror of
https://github.com/TomHarte/CLK.git
synced 2024-11-10 23:05:01 +00:00
a8645f80bf
i.e. sets of keys that don't amount to an entire keyboard in the modern sense. Experimentally used by the Master System for its reset key.
53 lines
1.3 KiB
C++
53 lines
1.3 KiB
C++
//
|
|
// Keyboard.cpp
|
|
// Clock Signal
|
|
//
|
|
// Created by Thomas Harte on 10/9/17.
|
|
// Copyright 2017 Thomas Harte. All rights reserved.
|
|
//
|
|
|
|
#include "Keyboard.hpp"
|
|
|
|
using namespace Inputs;
|
|
|
|
Keyboard::Keyboard() {
|
|
for(int k = 0; k < int(Key::Help); ++k) {
|
|
observed_keys_.insert(Key(k));
|
|
}
|
|
}
|
|
|
|
Keyboard::Keyboard(const std::set<Key> &observed_keys) : observed_keys_(observed_keys), is_exclusive_(false) {}
|
|
|
|
void Keyboard::set_key_pressed(Key key, char value, bool is_pressed) {
|
|
std::size_t key_offset = static_cast<std::size_t>(key);
|
|
if(key_offset >= key_states_.size()) {
|
|
key_states_.resize(key_offset+1, false);
|
|
}
|
|
key_states_[key_offset] = is_pressed;
|
|
|
|
if(delegate_) delegate_->keyboard_did_change_key(this, key, is_pressed);
|
|
}
|
|
|
|
void Keyboard::reset_all_keys() {
|
|
std::fill(key_states_.begin(), key_states_.end(), false);
|
|
if(delegate_) delegate_->reset_all_keys(this);
|
|
}
|
|
|
|
void Keyboard::set_delegate(Delegate *delegate) {
|
|
delegate_ = delegate;
|
|
}
|
|
|
|
bool Keyboard::get_key_state(Key key) {
|
|
std::size_t key_offset = static_cast<std::size_t>(key);
|
|
if(key_offset >= key_states_.size()) return false;
|
|
return key_states_[key_offset];
|
|
}
|
|
|
|
const std::set<Keyboard::Key> &Keyboard::observed_keys() {
|
|
return observed_keys_;
|
|
}
|
|
|
|
bool Keyboard::is_exclusive() {
|
|
return is_exclusive_;
|
|
}
|