mirror of
https://github.com/holub/mame
synced 2025-04-27 02:33:13 +03:00
input_sdl: Process control characters so that the natural keyboard can see them (SDL normally strips these out)
Don't strip linefeed characters (Ctrl-J) from natural keyboard input except when pasting strings
This commit is contained in:
parent
2b4c203d88
commit
197c94ceac
@ -17,7 +17,7 @@
|
|||||||
// DEBUGGING
|
// DEBUGGING
|
||||||
//**************************************************************************
|
//**************************************************************************
|
||||||
|
|
||||||
#define LOG_NATURAL_KEYBOARD 0
|
#define LOG_NATURAL_KEYBOARD 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -385,29 +385,32 @@ void natural_keyboard::set_in_use(bool usage)
|
|||||||
|
|
||||||
|
|
||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
// post - post a single character
|
// post_char - post a single character
|
||||||
//-------------------------------------------------
|
//-------------------------------------------------
|
||||||
|
|
||||||
void natural_keyboard::post(char32_t ch)
|
void natural_keyboard::post_char(char32_t ch, bool normalize_crlf)
|
||||||
{
|
{
|
||||||
// ignore any \n that are preceded by \r
|
if (normalize_crlf)
|
||||||
if (m_last_cr && ch == '\n')
|
|
||||||
{
|
{
|
||||||
m_last_cr = false;
|
// ignore any \n that are preceded by \r
|
||||||
return;
|
if (m_last_cr && ch == '\n')
|
||||||
}
|
{
|
||||||
|
m_last_cr = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// change all eolns to '\r'
|
// change all eolns to '\r'
|
||||||
if (ch == '\n')
|
if (ch == '\n')
|
||||||
ch = '\r';
|
ch = '\r';
|
||||||
else
|
else
|
||||||
m_last_cr = (ch == '\r');
|
m_last_cr = (ch == '\r');
|
||||||
|
}
|
||||||
|
|
||||||
// logging
|
// logging
|
||||||
if (LOG_NATURAL_KEYBOARD)
|
if (LOG_NATURAL_KEYBOARD)
|
||||||
{
|
{
|
||||||
const keycode_map_entry *code = find_code(ch);
|
const keycode_map_entry *code = find_code(ch);
|
||||||
machine().logerror("natural_keyboard::post(): code=%i (%s) field.name='%s'\n", int(ch), unicode_to_string(ch).c_str(), (code != nullptr && code->field[0] != nullptr) ? code->field[0]->name() : "<null>");
|
machine().logerror("natural_keyboard::post_char(): code=%i (%s) field.name='%s'\n", int(ch), unicode_to_string(ch).c_str(), (code != nullptr && code->field[0] != nullptr) ? code->field[0]->name() : "<null>");
|
||||||
}
|
}
|
||||||
|
|
||||||
// can we post this key in the queue directly?
|
// can we post this key in the queue directly?
|
||||||
@ -447,7 +450,7 @@ void natural_keyboard::post(const char32_t *text, size_t length, const attotime
|
|||||||
while (length > 0 && !full())
|
while (length > 0 && !full())
|
||||||
{
|
{
|
||||||
// fetch next character
|
// fetch next character
|
||||||
post(*text++);
|
post_char(*text++, true);
|
||||||
length--;
|
length--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -479,7 +482,7 @@ void natural_keyboard::post_utf8(const char *text, size_t length, const attotime
|
|||||||
}
|
}
|
||||||
|
|
||||||
// append to the buffer
|
// append to the buffer
|
||||||
post(uc);
|
post_char(uc, true);
|
||||||
text += count;
|
text += count;
|
||||||
length -= count;
|
length -= count;
|
||||||
}
|
}
|
||||||
@ -565,7 +568,7 @@ void natural_keyboard::post_coded(const char *text, size_t length, const attotim
|
|||||||
|
|
||||||
// if we got a code, post it
|
// if we got a code, post it
|
||||||
if (ch != 0)
|
if (ch != 0)
|
||||||
post(ch);
|
post_char(ch);
|
||||||
curpos += increment;
|
curpos += increment;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ public:
|
|||||||
void set_in_use(bool usage);
|
void set_in_use(bool usage);
|
||||||
|
|
||||||
// posting
|
// posting
|
||||||
void post(char32_t ch);
|
void post_char(char32_t ch, bool normalize_crlf = false);
|
||||||
void post(const char32_t *text, size_t length = 0, const attotime &rate = attotime::zero);
|
void post(const char32_t *text, size_t length = 0, const attotime &rate = attotime::zero);
|
||||||
void post_utf8(const char *text, size_t length = 0, const attotime &rate = attotime::zero);
|
void post_utf8(const char *text, size_t length = 0, const attotime &rate = attotime::zero);
|
||||||
void post_utf8(const std::string &text, const attotime &rate = attotime::zero);
|
void post_utf8(const std::string &text, const attotime &rate = attotime::zero);
|
||||||
|
@ -843,7 +843,7 @@ void mame_ui_manager::process_natural_keyboard()
|
|||||||
{
|
{
|
||||||
// if this was a UI_EVENT_CHAR event, post it
|
// if this was a UI_EVENT_CHAR event, post it
|
||||||
if (event.event_type == ui_event::IME_CHAR)
|
if (event.event_type == ui_event::IME_CHAR)
|
||||||
machine().ioport().natkeyboard().post(event.ch);
|
machine().ioport().natkeyboard().post_char(event.ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
// process natural keyboard keys that don't get UI_EVENT_CHARs
|
// process natural keyboard keys that don't get UI_EVENT_CHARs
|
||||||
@ -866,7 +866,7 @@ void mame_ui_manager::process_natural_keyboard()
|
|||||||
*key_down_ptr |= key_down_mask;
|
*key_down_ptr |= key_down_mask;
|
||||||
|
|
||||||
// post the key
|
// post the key
|
||||||
machine().ioport().natkeyboard().post(UCHAR_MAMEKEY_BEGIN + code.item_id());
|
machine().ioport().natkeyboard().post_char(UCHAR_MAMEKEY_BEGIN + code.item_id());
|
||||||
}
|
}
|
||||||
else if (!pressed && (*key_down_ptr & key_down_mask))
|
else if (!pressed && (*key_down_ptr & key_down_mask))
|
||||||
{
|
{
|
||||||
|
@ -386,6 +386,19 @@ public:
|
|||||||
keyboard.state[sdlevent.key.keysym.scancode] = 0x80;
|
keyboard.state[sdlevent.key.keysym.scancode] = 0x80;
|
||||||
if (sdlevent.key.keysym.sym < 0x20)
|
if (sdlevent.key.keysym.sym < 0x20)
|
||||||
machine().ui_input().push_char_event(osd_common_t::s_window_list.front()->target(), sdlevent.key.keysym.sym);
|
machine().ui_input().push_char_event(osd_common_t::s_window_list.front()->target(), sdlevent.key.keysym.sym);
|
||||||
|
else if (keyboard.state[SDL_SCANCODE_LCTRL] == 0x80 || keyboard.state[SDL_SCANCODE_RCTRL] == 0x80)
|
||||||
|
{
|
||||||
|
// SDL filters out control characters for text input, so they are decoded here
|
||||||
|
if (sdlevent.key.keysym.sym >= 0x40 && sdlevent.key.keysym.sym < 0x7f)
|
||||||
|
machine().ui_input().push_char_event(osd_common_t::s_window_list.front()->target(), sdlevent.key.keysym.sym & 0x1f);
|
||||||
|
else if (keyboard.state[SDL_SCANCODE_LSHIFT] == 0x80 || keyboard.state[SDL_SCANCODE_RSHIFT] == 0x80)
|
||||||
|
{
|
||||||
|
if (sdlevent.key.keysym.sym == SDLK_6) // Ctrl-^ (RS)
|
||||||
|
machine().ui_input().push_char_event(osd_common_t::s_window_list.front()->target(), 0x1e);
|
||||||
|
else if (sdlevent.key.keysym.sym == SDLK_MINUS) // Ctrl-_ (US)
|
||||||
|
machine().ui_input().push_char_event(osd_common_t::s_window_list.front()->target(), 0x1f);
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
|
Loading…
Reference in New Issue
Block a user