저는 C++로 자체 텍스트 편집기를 구현하고 있습니다. 그럴거야 ... 좋아. ; P스캔 코드를 ASCII로 변환
키 코드 (특히 Allegro, 스캔 코드라고 부름)를 ASCII-char로 변환하는 방법이 필요합니다. 나는 A-Z를 쉽게 할 수 있고, A-Z로 변환하는 것은 쉽다. 현재 내가하는 일은 Allegro에서 scancode (al_keycode_to_name)에서 이름을 반환하는 함수를 사용하는 것입니다. 즉, 눌려진 키가 A-Z이면 "A"를 "Z"로 반환합니다. 그건 쉬운 말이지 만 ",", ";"와 같은 특수 문자를 읽을 수는 없습니다. 그게 내가 힘든 시간을 보내고있는 곳이야.
자동으로이 작업을 수행 할 수있는 방법이 있습니까? 아마도 이것을하는 도서관일까요? 실제 트릭은 다른 레이아웃을 고려하고 있습니다.
다음은 내가 지금까지 가지고있는 것입니다.
void AllegroInput::TextInput(const InputState &inputState, int ¤tCharacter, int ¤tRow, std::string &textString)
{
static int keyTimer = 0;
static const int KEY_TIMER_LIMIT = 15;
for (int i = 0; i < 255; i++)
{
if (inputState.key[i].keyDown)
{
keyTimer++;
}
if (inputState.key[i].keyPress)
{
keyTimer = 0;
}
if ((inputState.key[i].keyPress) || ((inputState.key[i].keyDown) && (keyTimer >= KEY_TIMER_LIMIT)))
{
std::string ASCII = al_keycode_to_name(i);
if ((ASCII.c_str()[0] >= 32) && (ASCII.c_str()[0] <= 126) && (ASCII.length() == 1))
{
textString = textString.substr(0, currentCharacter) + ASCII + textString.substr(currentCharacter, textString.length());
currentCharacter++;
}
else
{
switch(i)
{
case ALLEGRO_KEY_DELETE:
if (currentCharacter >= 0)
{
textString.erase(currentCharacter, 1);
}
break;
case ALLEGRO_KEY_BACKSPACE:
if (currentCharacter > 0)
{
currentCharacter--;
textString.erase(currentCharacter, 1);
}
break;
case ALLEGRO_KEY_RIGHT:
if (currentCharacter < textString.length())
{
currentCharacter++;
}
break;
case ALLEGRO_KEY_LEFT:
if (currentCharacter > 0)
{
currentCharacter--;
}
break;
case ALLEGRO_KEY_SPACE:
if (currentCharacter > 0)
{
textString = textString.substr(0, currentCharacter) + " " + textString.substr(currentCharacter, textString.length());
currentCharacter++;
}
break;
}
}
}
}
}
내가 할 수 있다는 것을 깨닫지 못했습니다, 감사합니다! –