2016-11-05 18:47:09 +00:00
|
|
|
//
|
|
|
|
// KeyboardMachine.h
|
|
|
|
// Clock Signal
|
|
|
|
//
|
|
|
|
// Created by Thomas Harte on 05/11/2016.
|
2018-05-13 19:19:52 +00:00
|
|
|
// Copyright 2016 Thomas Harte. All rights reserved.
|
2016-11-05 18:47:09 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#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>
|
2019-09-22 17:14:09 +00:00
|
|
|
#include <set>
|
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 {
|
|
|
|
|
2018-03-09 20:19:02 +00:00
|
|
|
/*!
|
|
|
|
Covers just the actions necessary to communicate keyboard state, as a purely abstract class.
|
|
|
|
*/
|
|
|
|
struct KeyActions {
|
|
|
|
/*!
|
|
|
|
Indicates that the key @c key has been either pressed or released, according to
|
|
|
|
the state of @c isPressed.
|
|
|
|
*/
|
2018-04-16 01:11:30 +00:00
|
|
|
virtual void set_key_state(uint16_t key, bool is_pressed) {}
|
2018-03-09 20:19:02 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Instructs that all keys should now be treated as released.
|
|
|
|
*/
|
2018-04-16 01:11:30 +00:00
|
|
|
virtual void clear_all_keys() {}
|
2018-03-09 20:19:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
2018-10-25 01:59:30 +00:00
|
|
|
Describes an emulated machine which exposes a keyboard and accepts a typed string.
|
2018-03-09 20:19:02 +00:00
|
|
|
*/
|
2018-10-25 01:59:30 +00:00
|
|
|
class Machine: public KeyActions {
|
2016-11-05 18:47:09 +00:00
|
|
|
public:
|
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.
|
|
|
|
*/
|
2018-10-25 01:59:30 +00:00
|
|
|
virtual Inputs::Keyboard &get_keyboard() = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Provides a base class for machines that want to provide a keyboard mapper,
|
|
|
|
allowing automatic mapping from keyboard inputs to KeyActions.
|
|
|
|
*/
|
|
|
|
class MappedMachine: public Inputs::Keyboard::Delegate, public Machine {
|
|
|
|
public:
|
2019-09-22 17:48:50 +00:00
|
|
|
MappedMachine(const std::set<Inputs::Keyboard::Key> &essential_modifiers = {});
|
2017-10-13 02:25:02 +00:00
|
|
|
|
|
|
|
/*!
|
|
|
|
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;
|
|
|
|
|
|
|
|
/*!
|
|
|
|
Allows individual machines to provide the mapping between host keys
|
|
|
|
as per Inputs::Keyboard and their native scheme.
|
|
|
|
*/
|
2018-02-09 21:31:05 +00:00
|
|
|
virtual KeyboardMapper *get_keyboard_mapper();
|
2017-10-13 02:25:02 +00:00
|
|
|
|
2018-10-25 01:59:30 +00:00
|
|
|
/*!
|
|
|
|
Provides a keyboard that obtains this machine's keyboard mapper, maps
|
|
|
|
the key and supplies it via the KeyActions.
|
|
|
|
*/
|
|
|
|
virtual Inputs::Keyboard &get_keyboard() override;
|
|
|
|
|
2017-10-13 02:25:02 +00:00
|
|
|
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 */
|