-attempt to be friendlier on non english keyboards

This commit is contained in:
Juan Linietsky 2015-01-04 22:39:21 -03:00
parent 8c4dd8de39
commit 1ff0d5c4e5
7 changed files with 203 additions and 103 deletions

View File

@ -27,7 +27,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "keyboard.h"
#include "os/os.h"
struct _KeyCodeText {
int code;
@ -354,7 +354,105 @@ int find_keycode(const String& p_code) {
}
int latin_keyboard_keycode_convert(int p_keycode){
struct _KeyCodeReplace {
int from;
int to;
};
static const _KeyCodeReplace _keycode_replace_qwertz[]={
{KEY_Y,KEY_Z},
{KEY_Z,KEY_Y},
{0,0}
};
static const _KeyCodeReplace _keycode_replace_azerty[]={
{KEY_W,KEY_Z},
{KEY_Z,KEY_W},
{KEY_A,KEY_Q},
{KEY_Q,KEY_A},
{KEY_SEMICOLON,KEY_M},
{KEY_M,KEY_SEMICOLON},
{0,0}
};
static const _KeyCodeReplace _keycode_replace_qzerty[]={
{KEY_W,KEY_Z},
{KEY_Z,KEY_W},
{KEY_SEMICOLON,KEY_M},
{KEY_M,KEY_SEMICOLON},
{0,0}
};
static const _KeyCodeReplace _keycode_replace_dvorak[]={
{KEY_UNDERSCORE,KEY_BRACELEFT},
{KEY_EQUAL,KEY_BRACERIGHT},
{KEY_Q,KEY_APOSTROPHE},
{KEY_W,KEY_COMMA},
{KEY_E,KEY_PERIOD},
{KEY_R,KEY_P},
{KEY_T,KEY_Y},
{KEY_Y,KEY_F},
{KEY_U,KEY_G},
{KEY_I,KEY_C},
{KEY_O,KEY_R},
{KEY_P,KEY_L},
{KEY_BRACELEFT,KEY_SLASH},
{KEY_BRACERIGHT,KEY_EQUAL},
{KEY_A,KEY_A},
{KEY_S,KEY_O},
{KEY_D,KEY_E},
{KEY_F,KEY_U},
{KEY_G,KEY_I},
{KEY_H,KEY_D},
{KEY_J,KEY_H},
{KEY_K,KEY_T},
{KEY_L,KEY_N},
{KEY_SEMICOLON,KEY_S},
{KEY_APOSTROPHE,KEY_UNDERSCORE},
{KEY_Z,KEY_SEMICOLON},
{KEY_X,KEY_Q},
{KEY_C,KEY_J},
{KEY_V,KEY_K},
{KEY_B,KEY_X},
{KEY_N,KEY_B},
{KEY_M,KEY_M},
{KEY_COMMA,KEY_W},
{KEY_PERIOD,KEY_V},
{KEY_SLASH,KEY_Z},
{0,0}
};
static const _KeyCodeReplace _keycode_replace_neo[]={
{0,0}
};
int latin_keyboard_keycode_convert(int p_keycode) {
const _KeyCodeReplace *kcr=NULL;
switch(OS::get_singleton()->get_latin_keyboard_variant()) {
case OS::LATIN_KEYBOARD_QWERTY: return p_keycode; break;
case OS::LATIN_KEYBOARD_QWERTZ: kcr=_keycode_replace_qwertz; break;
case OS::LATIN_KEYBOARD_AZERTY: kcr=_keycode_replace_azerty; break;
case OS::LATIN_KEYBOARD_QZERTY: kcr=_keycode_replace_qzerty; break;
case OS::LATIN_KEYBOARD_DVORAK: kcr=_keycode_replace_dvorak; break;
case OS::LATIN_KEYBOARD_NEO: kcr=_keycode_replace_neo; break;
default: return p_keycode;
}
if (!kcr) {
return p_keycode;
}
while(kcr->from) {
if (kcr->from==p_keycode)
return kcr->to;
kcr++;
}
return p_keycode;
}

View File

@ -1222,9 +1222,9 @@ GridMapEditor::GridMapEditor(EditorNode *p_editor) {
options->get_popup()->add_item("Cursor Rotate X",MENU_OPTION_CURSOR_ROTATE_X,KEY_A);
options->get_popup()->add_item("Cursor Rotate Y",MENU_OPTION_CURSOR_ROTATE_Y,KEY_S);
options->get_popup()->add_item("Cursor Rotate Z",MENU_OPTION_CURSOR_ROTATE_Z,KEY_D);
options->get_popup()->add_item("Cursor Back Rotate X",MENU_OPTION_CURSOR_ROTATE_X,KEY_ALT+KEY_A);
options->get_popup()->add_item("Cursor Back Rotate Y",MENU_OPTION_CURSOR_ROTATE_Y,KEY_ALT+KEY_S);
options->get_popup()->add_item("Cursor Back Rotate Z",MENU_OPTION_CURSOR_ROTATE_Z,KEY_ALT+KEY_D);
options->get_popup()->add_item("Cursor Back Rotate X",MENU_OPTION_CURSOR_ROTATE_X,KEY_MASK_SHIFT+KEY_A);
options->get_popup()->add_item("Cursor Back Rotate Y",MENU_OPTION_CURSOR_ROTATE_Y,KEY_MASK_SHIFT+KEY_S);
options->get_popup()->add_item("Cursor Back Rotate Z",MENU_OPTION_CURSOR_ROTATE_Z,KEY_MASK_SHIFT+KEY_D);
options->get_popup()->add_item("Cursor Clear Rotation",MENU_OPTION_CURSOR_CLEAR_ROTATION,KEY_W);
options->get_popup()->add_separator();
options->get_popup()->add_check_item("Duplicate Selects",MENU_OPTION_DUPLICATE_SELECTS);

View File

@ -694,7 +694,7 @@ static int translateKey(unsigned int key)
ev.type=InputEvent::KEY;
ev.key.pressed=true;
ev.key.mod=translateFlags([event modifierFlags]);
ev.key.scancode = translateKey([event keyCode]);
ev.key.scancode = latin_keyboard_keycode_convert(translateKey([event keyCode]));
ev.key.echo = [event isARepeat];
NSString* characters = [event characters];
@ -740,7 +740,7 @@ static int translateKey(unsigned int key)
ev.type=InputEvent::KEY;
ev.key.pressed=false;
ev.key.mod=translateFlags([event modifierFlags]);
ev.key.scancode = translateKey([event keyCode]);
ev.key.scancode = latin_keyboard_keycode_convert(translateKey([event keyCode]));
OS_OSX::singleton->push_input(ev);

View File

@ -1293,106 +1293,108 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
break;
bool valid=true;
if (k.mod.command || k.mod.alt || k.mod.meta)
if (k.mod.command || k.mod.meta)
valid=false;
if (valid) {
if (k.scancode==KEY_UP) {
if (completion_index>0) {
completion_index--;
if (!k.mod.alt) {
if (k.scancode==KEY_UP) {
if (completion_index>0) {
completion_index--;
completion_current=completion_options[completion_index];
update();
}
accept_event();
return;
}
if (k.scancode==KEY_DOWN) {
if (completion_index<completion_options.size()-1) {
completion_index++;
completion_current=completion_options[completion_index];
update();
}
accept_event();
return;
}
if (k.scancode==KEY_PAGEUP) {
completion_index-=get_constant("completion_lines");
if (completion_index<0)
completion_index=0;
completion_current=completion_options[completion_index];
update();
accept_event();
return;
}
accept_event();
return;
}
if (k.scancode==KEY_DOWN) {
if (completion_index<completion_options.size()-1) {
completion_index++;
if (k.scancode==KEY_PAGEDOWN) {
completion_index+=get_constant("completion_lines");
if (completion_index>=completion_options.size())
completion_index=completion_options.size()-1;
completion_current=completion_options[completion_index];
update();
accept_event();
return;
}
accept_event();
return;
}
if (k.scancode==KEY_PAGEUP) {
completion_index-=get_constant("completion_lines");
if (completion_index<0)
if (k.scancode==KEY_HOME) {
completion_index=0;
completion_current=completion_options[completion_index];
update();
accept_event();
return;
}
if (k.scancode==KEY_PAGEDOWN) {
completion_index+=get_constant("completion_lines");
if (completion_index>=completion_options.size())
completion_index=completion_options.size()-1;
completion_current=completion_options[completion_index];
update();
accept_event();
return;
}
if (k.scancode==KEY_HOME) {
completion_index=0;
completion_current=completion_options[completion_index];
update();
accept_event();
return;
}
if (k.scancode==KEY_END) {
completion_index=completion_options.size()-1;
completion_current=completion_options[completion_index];
update();
accept_event();
return;
}
if (k.scancode==KEY_DOWN) {
if (completion_index<completion_options.size()-1) {
completion_index++;
completion_current=completion_options[completion_index];
update();
accept_event();
return;
}
if (k.scancode==KEY_END) {
completion_index=completion_options.size()-1;
completion_current=completion_options[completion_index];
update();
accept_event();
return;
}
if (k.scancode==KEY_DOWN) {
if (completion_index<completion_options.size()-1) {
completion_index++;
completion_current=completion_options[completion_index];
update();
}
accept_event();
return;
}
if (k.scancode==KEY_RETURN || k.scancode==KEY_TAB) {
_confirm_completion();
accept_event();
return;
}
if (k.scancode==KEY_BACKSPACE) {
backspace_at_cursor();
_update_completion_candidates();
accept_event();
return;
}
if (k.scancode==KEY_SHIFT) {
accept_event();
return;
}
accept_event();
return;
}
if (k.scancode==KEY_RETURN || k.scancode==KEY_TAB) {
_confirm_completion();
accept_event();
return;
}
if (k.scancode==KEY_BACKSPACE) {
backspace_at_cursor();
_update_completion_candidates();
accept_event();
return;
}
if (k.scancode==KEY_SHIFT) {
accept_event();
return;
}
if (k.unicode>32) {
@ -1972,7 +1974,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
} break;
case KEY_U:{
if (!k.mod.command || k.mod.shift || k.mod.alt) {
if (!k.mod.command || k.mod.shift) {
scancode_handled=false;
break;
}
@ -2018,7 +2020,7 @@ void TextEdit::_input_event(const InputEvent& p_input_event) {
}
}
*/
if (!scancode_handled && !k.mod.command && !k.mod.alt) { //for german kbds
if (!scancode_handled && !k.mod.command) { //for german kbds
if (k.unicode>=32) {

View File

@ -2888,7 +2888,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) {
p->add_separator();
p->add_item("Copy Pose",ANIM_COPY_POSE);
p->add_item("Paste Pose",ANIM_PASTE_POSE);
p->add_item("Clear Pose",ANIM_CLEAR_POSE,KEY_MASK_ALT|KEY_K);
p->add_item("Clear Pose",ANIM_CLEAR_POSE,KEY_MASK_SHIFT|KEY_K);
value_dialog = memnew( AcceptDialog );
value_dialog->set_title("Set a Value");

View File

@ -1578,7 +1578,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) {
menu_hb->add_child(file_menu);
file_menu->set_text("File");
file_menu->get_popup()->add_item("Open",FILE_OPEN);
file_menu->get_popup()->add_item("Save",FILE_SAVE,KEY_MASK_ALT|KEY_S);
file_menu->get_popup()->add_item("Save",FILE_SAVE,KEY_MASK_ALT|KEY_MASK_CMD|KEY_S);
file_menu->get_popup()->add_item("Save As..",FILE_SAVE_AS);
file_menu->get_popup()->add_item("Save All",FILE_SAVE_ALL,KEY_MASK_CMD|KEY_MASK_SHIFT|KEY_S);
file_menu->get_popup()->connect("item_pressed", this,"_menu_option");

View File

@ -3650,12 +3650,12 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) {
p->add_check_item("Use Default sRGB",MENU_VIEW_USE_DEFAULT_SRGB);
p->add_separator();
p->add_check_item("1 Viewport",MENU_VIEW_USE_1_VIEWPORT,KEY_MASK_ALT+KEY_1);
p->add_check_item("2 Viewports",MENU_VIEW_USE_2_VIEWPORTS,KEY_MASK_ALT+KEY_2);
p->add_check_item("2 Viewports (Alt)",MENU_VIEW_USE_2_VIEWPORTS_ALT,KEY_MASK_SHIFT+KEY_MASK_ALT+KEY_2);
p->add_check_item("3 Viewports",MENU_VIEW_USE_3_VIEWPORTS,KEY_MASK_ALT+KEY_3);
p->add_check_item("3 Viewports (Alt)",MENU_VIEW_USE_3_VIEWPORTS_ALT,KEY_MASK_SHIFT+KEY_MASK_ALT+KEY_3);
p->add_check_item("4 Viewports",MENU_VIEW_USE_4_VIEWPORTS,KEY_MASK_ALT+KEY_4);
p->add_check_item("1 Viewport",MENU_VIEW_USE_1_VIEWPORT,KEY_MASK_CMD+KEY_1);
p->add_check_item("2 Viewports",MENU_VIEW_USE_2_VIEWPORTS,KEY_MASK_CMD+KEY_2);
p->add_check_item("2 Viewports (Alt)",MENU_VIEW_USE_2_VIEWPORTS_ALT,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_2);
p->add_check_item("3 Viewports",MENU_VIEW_USE_3_VIEWPORTS,KEY_MASK_CMD+KEY_3);
p->add_check_item("3 Viewports (Alt)",MENU_VIEW_USE_3_VIEWPORTS_ALT,KEY_MASK_SHIFT+KEY_MASK_CMD+KEY_3);
p->add_check_item("4 Viewports",MENU_VIEW_USE_4_VIEWPORTS,KEY_MASK_CMD+KEY_4);
p->add_separator();
p->add_check_item("Display Normal",MENU_VIEW_DISPLAY_NORMAL);