キーボード入力でローマ字入力したいです。(例えばohayouを「おはよう」としたいです。)
リファレンスを見たところ int DrawKeyInputModeString( int x , int y ) を使えると思ったのですが、
どのように使えばよいかサンプルのプログラムがありませんでした。
関数DrawKeyInputModeStringはキー入力のローマ字入力は出来るのでしょうか?
以下は私が書いたわけではないのですが、キーを半角のアルファベットのまま描画するプログラムです。
#include "DxLib.h"
struct key_table { int key; char val; } table[] = {
{ KEY_INPUT_A, 'a' }, { KEY_INPUT_B, 'b' }, { KEY_INPUT_C, 'c' },
{ KEY_INPUT_D, 'd' }, { KEY_INPUT_E, 'e' }, { KEY_INPUT_F, 'f' },
{ KEY_INPUT_G, 'g' }, { KEY_INPUT_H, 'h' }, { KEY_INPUT_I, 'i' },
{ KEY_INPUT_J, 'j' }, { KEY_INPUT_K, 'k' }, { KEY_INPUT_L, 'l' },
{ KEY_INPUT_M, 'm' }, { KEY_INPUT_N, 'n' }, { KEY_INPUT_O, 'o' },
{ KEY_INPUT_P, 'p' }, { KEY_INPUT_Q, 'q' }, { KEY_INPUT_R, 'r' },
{ KEY_INPUT_S, 's' }, { KEY_INPUT_T, 't' }, { KEY_INPUT_U, 'u' },
{ KEY_INPUT_V, 'v' }, { KEY_INPUT_W, 'w' }, { KEY_INPUT_X, 'x' },
{ KEY_INPUT_Y, 'y' }, { KEY_INPUT_Z, 'z' }, { KEY_INPUT_0, '0' },
{ KEY_INPUT_1, '1' }, { KEY_INPUT_2, '2' }, { KEY_INPUT_3, '3' },
{ KEY_INPUT_4, '4' }, { KEY_INPUT_5, '5' }, { KEY_INPUT_6, '6' },
{ KEY_INPUT_7, '7' }, { KEY_INPUT_8, '8' }, { KEY_INPUT_9, '9' },
{ KEY_INPUT_SPACE, ' ' }, { KEY_INPUT_MINUS, '-' },
{ KEY_INPUT_YEN, '\\' }, { KEY_INPUT_PREVTRACK, '^' },
{ KEY_INPUT_PERIOD, '.' }, { KEY_INPUT_SLASH, '/' },
{ KEY_INPUT_SEMICOLON, ';' }, { KEY_INPUT_COLON, ':' },
{ KEY_INPUT_LBRACKET, '[' }, { KEY_INPUT_RBRACKET, ']' },
{ KEY_INPUT_AT, '@' }, { KEY_INPUT_COMMA, ',' },
};
const int table_size = sizeof(table) / sizeof(*table);
void gpUpdateKey(int Key[])
{
char tmpKey[256];
GetHitKeyStateAll(tmpKey);
for (int i = 0; i < 256; i++)
if (tmpKey[i] != 0) Key[i]++;
else Key[i] = 0;
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
SetGraphMode(960, 720, 32); // ウィンドウの大きさを指定
ChangeWindowMode(TRUE); // 全画面ではなくウインドウを使用
if (DxLib_Init() == -1) return -1; // DXライブラリ初期化処理
SetDrawScreen(DX_SCREEN_BACK); // 裏画面を使用する設定
unsigned int Cr = GetColor(255, 255, 255); // 白色の値を取得
char str[1024] = "";
int len = 0;
int Key[256];
while (ProcessMessage() == 0) {
gpUpdateKey(Key);
for (int i = 0; i < table_size; i++)
if (Key[table[i].key] == 1) str[len++] = table[i].val;
ClearDrawScreen();
DrawString(250, 240 - 32, str, Cr);
DrawKeyInputModeString(250, 240);
ScreenFlip();
}
DxLib_End();
return 0;
}