--- nono/vm/keyboard.cpp 2026/04/29 17:05:18 1.1.1.11 +++ nono/vm/keyboard.cpp 2026/04/29 17:05:43 1.1.1.16 @@ -88,7 +88,7 @@ // MakeKey()/BreakKey() : // | // | KEY_INPUT Message : -// | - - - - - - - - - - - -> KeyInputCallback() +// | - - - - - - - - - - - -> KeyInputMessage() // o | // : MD::KeyInput() // | @@ -105,10 +105,30 @@ #include "uimessage.h" #include +// +// 文字入力しか持たないキーボードの下位クラス +// + // コンストラクタ -Keyboard::Keyboard() +DumbKeyboard::DumbKeyboard() : inherited(OBJ_KEYBOARD) { +} + +// デストラクタ +DumbKeyboard::~DumbKeyboard() +{ +} + + +// +// 通常のキーボード +// + +// コンストラクタ +Keyboard::Keyboard() + : inherited() +{ pressed.resize(KC_max); } @@ -121,14 +141,10 @@ Keyboard::~Keyboard() bool Keyboard::Init() { - if (inherited::Init() == false) { - return false; - } - syncer = GetSyncer(); scheduler->ConnectMessage(MessageID::KEY_INPUT, this, - ToMessageCallback(&Keyboard::KeyInputCallback)); + ToMessageCallback(&Keyboard::KeyInputMessage)); return true; } @@ -236,7 +252,7 @@ Keyboard::CharInput(uint charcode) // キー入力メッセージコールバック void -Keyboard::KeyInputCallback(MessageID msgid, uint32 arg) +Keyboard::KeyInputMessage(MessageID msgid, uint32 arg) { uint keystat = arg; switch (keystat) { @@ -289,6 +305,27 @@ Keyboard::DoDisconnect() UIMessage::Post(UIMessage::KEYBOARD); } +// キーの押し下げ状態を設定する。 +// 初期化時以外で pressed を変更するときはこの関数を使用すること。 +void +Keyboard::SetPressed(uint keycode, bool ismake) +{ + // キーがどれか1つでも押されてる間は VM の高速実行を抑制する。 + // すべてのキーが離されたら高速モードを許可する。 + if (ismake) { + bool prev = Any(); + pressed[keycode] = true; + if (prev == false) { + syncer->RequestKeyPressed(true); + } + } else { + pressed[keycode] = false; + if (Any() == false) { + syncer->RequestKeyPressed(false); + } + } +} + // キー入力を1つ処理する。 // keystat が押下・開放されたキーの物理的な状態。 // キー入力を受け取らずに破棄した場合は false を返す。 @@ -315,7 +352,7 @@ Keyboard::KeyInputCommon(uint keystat) if (loglevel >= 1) { std::string msg; - msg += string_format("%d(", keycode); + msg += string_format("%u(", keycode); msg += GetKeyName(keycode); msg += ")"; @@ -340,20 +377,7 @@ Keyboard::KeyInputCommon(uint keystat) } } - // キーがどれか1つでも押されてる間は VM の高速実行を抑制する。 - // すべてのキーが離されたら高速モードを許可する。 - if (ismake) { - bool prev = Any(); - pressed[keycode] = true; - if (prev == false) { - syncer->RequestKeyPressed(true); - } - } else { - pressed[keycode] = false; - if (Any() == false) { - syncer->RequestKeyPressed(false); - } - } + SetPressed(keycode, ismake); // キーの状態が変わったので UI に通知。 // KC_FLAG_POST が立っていればキーコードも送信 (char 入力モード用)。