2016-11-05 18:47:09 +00:00
|
|
|
//
|
|
|
|
// KeyboardMachine.h
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 05/11/2016.
|
|
|
|
// Copyright © 2016 Thomas Harte. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef KeyboardMachine_h
|
|
|
|
#define KeyboardMachine_h
|
|
|
|
|
2017-11-10 03:04:49 +00:00
|
|
|
#include <cstdint>
|
2017-12-29 23:41:26 +00:00
|
|
|
#include <string>
|
2017-11-10 03:04:49 +00:00
|
|
|
|
2017-10-13 02:25:02 +00:00
|
|
|
#include "../Inputs/Keyboard.hpp"
|
|
|
|
|
2016-11-05 18:47:09 +00:00
|
|
|
namespace KeyboardMachine {
|
|
|
|
|
2017-10-13 02:25:02 +00:00
|
|
|
class Machine: public Inputs::Keyboard::Delegate {
|
2016-11-05 18:47:09 +00:00
|
|
|
public:
|
2017-10-13 02:25:02 +00:00
|
|
|
Machine();
|
2017-11-08 03:51:06 +00:00
|
|
|
|
2017-07-22 21:39:51 +00:00
|
|
|
/*!
|
|
|
|
Indicates that the key @c key has been either pressed or released, according to
|
|
|
|
the state of @c isPressed.
|
|
|
|
*/
|
2017-10-13 02:25:02 +00:00
|
|
|
virtual void set_key_state(uint16_t key, bool is_pressed) = 0;
|
2017-07-22 21:39:51 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Instructs that all keys should now be treated as released.
|
|
|
|
*/
|
2016-11-05 18:47:09 +00:00
|
|
|
virtual void clear_all_keys() = 0;
|
2017-10-13 02:25:02 +00:00
|
|
|
|
2017-12-29 23:30:46 +00:00
|
|
|
/*!
|
|
|
|
Causes the machine to attempt to type the supplied string.
|
|
|
|
|
|
|
|
This is best effort. Success or failure is permitted to be a function of machine and current state.
|
|
|
|
*/
|
|
|
|
virtual void type_string(const std::string &);
|
|
|
|
|
2017-10-13 02:25:02 +00:00
|
|
|
/*!
|
|
|
|
Provides a destination for keyboard input.
|
|
|
|
*/
|
|
|
|
virtual Inputs::Keyboard &get_keyboard();
|
|
|
|
|
|
|
|
/*!
|
|
|
|
A keyboard mapper attempts to provide a physical mapping between host keys and emulated keys.
|
|
|
|
See the character mapper for logical mapping.
|
|
|
|
*/
|
|
|
|
class KeyboardMapper {
|
|
|
|
public:
|
|
|
|
virtual uint16_t mapped_key_for_key(Inputs::Keyboard::Key key) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// Terminates a key sequence from the character mapper.
|
|
|
|
static const uint16_t KeyEndSequence = 0xffff;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Indicates that a key is not mapped (for the keyboard mapper) or that a
|
|
|
|
character cannot be typed (for the character mapper).
|
|
|
|
*/
|
|
|
|
static const uint16_t KeyNotMapped = 0xfffe;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/*!
|
|
|
|
Allows individual machines to provide the mapping between host keys
|
|
|
|
as per Inputs::Keyboard and their native scheme.
|
|
|
|
*/
|
|
|
|
virtual KeyboardMapper &get_keyboard_mapper() = 0;
|
|
|
|
|
|
|
|
private:
|
2017-10-15 02:07:11 +00:00
|
|
|
void keyboard_did_change_key(Inputs::Keyboard *keyboard, Inputs::Keyboard::Key key, bool is_pressed) override;
|
|
|
|
void reset_all_keys(Inputs::Keyboard *keyboard) override;
|
2017-10-13 02:25:02 +00:00
|
|
|
Inputs::Keyboard keyboard_;
|
2016-11-05 18:47:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* KeyboardMachine_h */
|