Jump to content

Vaisr

Members
  • Posts

    7
  • Joined

  • Last visited

Everything posted by Vaisr

  1. Also, there is another problem that has not been discussed in this thread. I would like to share it with you. Given that we have a lot of keyboard layouts, there is some problem, if we click on the button to increase the characters once and select and click the desired character (in my case, either Ukrainian or Russian layout), the layout will reset to English. I also solved this problem, and the file is located in ugfx/src/gwin/gwin/gwin_keybord.c Line about 213 and the method KeyMouseUp. The contents of the code itself: I was commenting on what I changed // A mouse up has occurred (it may or may not be over the button) static void KeyMouseUp(GWidgetObject *gw, gCoord x, gCoord y) { #define gk ((GKeyboardObject *)gw) KeyFindKey(gk, x, y); // Do we have a valid key? if (gk->keyrow == GKEY_BAD_ROWCOL) { if (gk->lastkeyrow != GKEY_BAD_ROWCOL) { gw->g.flags |= GKEYBOARD_FLG_QUICKUPDATE; _gwinUpdate((GHandle)gw); } return; } // We are turning off the display of the key gk->keyrow = gk->keycol = GKEY_BAD_ROWCOL; // Is this one of the special keys if (gk->key < 0x20) { // This is a special key const GVSpecialKey *skey; skey = &gk->keytable->skeys[gk->key - 1]; if ((skey->flags & GVKEY_SINGLESET)) { // Single character switch to a new layout gk->keyset = gk->keytable->ksets[skey->newset]; gk->w.g.flags &= ~(GKEYBOARD_FLG_QUICKUPDATE|GKEYBOARD_FLG_REVERTSET); gk->w.g.flags |= GKEYBOARD_FLG_REVERTSET; } else if ((skey->flags & GVKEY_LOCKSET)) { // Locked switch to a new layout gk->keyset = gk->keytable->ksets[skey->newset]; gk->w.g.flags &= ~(GKEYBOARD_FLG_QUICKUPDATE|GKEYBOARD_FLG_REVERTSET); } else if ((gk->w.g.flags & GKEYBOARD_FLG_REVERTSET)) { // Revert to default layout // **Фикс:** Сбрасываем только регистр, не меняя раскладку if (gk->keyset == gk->keytable->ksets[6]) { gk->keyset = gk->keytable->ksets[5]; // Русский регистр вниз } else if (gk->keyset == gk->keytable->ksets[9]) { gk->keyset = gk->keytable->ksets[8]; // Украинский регистр вниз } else { gk->keyset = gk->keytable->ksets[0]; // Английский регистр вниз } gk->w.g.flags &= ~(GKEYBOARD_FLG_QUICKUPDATE|GKEYBOARD_FLG_REVERTSET); } else { // Just turning off a key gw->g.flags |= GKEYBOARD_FLG_QUICKUPDATE; } // Send the key if required if (skey->sendkey && skey->sendkey[0]) SendVirtualKeyEvent(gk); // Update the display _gwinUpdate((GHandle)gw); return; } // Do we need to revert to the standard layout? if ((gk->w.g.flags & GKEYBOARD_FLG_REVERTSET)) { // **Фикс:** Сбрасываем только регистр, не меняя раскладку if (gk->keyset == gk->keytable->ksets[6]) { gk->keyset = gk->keytable->ksets[5]; // Русский регистр вниз } else if (gk->keyset == gk->keytable->ksets[9]) { gk->keyset = gk->keytable->ksets[8]; // Украинский регистр вниз } else { gk->keyset = gk->keytable->ksets[0]; // Английский регистр вниз } gk->w.g.flags &= ~(GKEYBOARD_FLG_QUICKUPDATE|GKEYBOARD_FLG_REVERTSET); } else { gw->g.flags |= GKEYBOARD_FLG_QUICKUPDATE; } // Send the key SendVirtualKeyEvent(gk); // Update the display _gwinUpdate((GHandle)gw); }
  2. I also added another keyboard layout (Ukrainian). Maybe someone will need it: #if GWIN_NEED_KEYBOARD_ENGLISH1 /* For this keyboard mapping we use: * Set 0 = Lowercase letters * Set 1 = Uppercase letters (transient) * Set 2 = Uppercase letters (locked) * Set 3 = Numbers * Set 4 = Symbols */ static const GVSpecialKey Eng1SKeys[] = { { "\001", 0, GVKEY_SINGLESET, 1 }, // \001 (1) = Shift Lower to Upper { "\001", 0, GVKEY_INVERT|GVKEY_LOCKSET, 2 }, // \002 (2) = Shift Upper to Upper Lock { "\002", 0, GVKEY_INVERT|GVKEY_LOCKSET, 0}, // \003 (3) = Shift Upper Lock to Lower { "123", 0, GVKEY_LOCKSET, 3 }, // \004 (4) = Change to Numbers { "\010", "\b", 0, 0 }, // \005 (5) = Backspace { "\015", "\r", 0, 0 }, // \006 (6) = Enter 1 { "\015", "\r", 0, 0 }, // \007 (7) = Enter 2 (Short keycap) { "Sym", 0, GVKEY_LOCKSET, 4 }, // \010 (8) = Change to Symbols { "aA", 0, GVKEY_LOCKSET, 0 }, // \011 (9) = Change to Lower Alphab { "RU", 0, GVKEY_LOCKSET, 5 }, // \012 (10) = Change to Russian { "UA", 0, GVKEY_LOCKSET, 8 }, // \013 (11) = Change to Ukrainian { "EN", 0, GVKEY_LOCKSET, 0 }, // \014 (12) = Change to English { "\001", 0, GVKEY_SINGLESET, 6 }, // \015 (13) = Shift Lower to Upper { "\001", 0, GVKEY_INVERT|GVKEY_LOCKSET, 7 }, // \016 (14) = Shift Upper to Upper Lock { "\002", 0, GVKEY_INVERT|GVKEY_LOCKSET, 5 }, // \017 (15) = Shift Upper Lock to Lower { "\001", 0, GVKEY_SINGLESET, 9 }, // \020 (16) = Shift Lower to Upper { "\001", 0, GVKEY_INVERT|GVKEY_LOCKSET, 10 }, // \021 (17) = Shift Upper to Upper Lock { "\002", 0, GVKEY_INVERT|GVKEY_LOCKSET, 8 } // \022 (18) = Shift Upper Lock to Lower }; static const char Eng1Set0Row3[] = "\004\012 .\006\006"; static const char Ru1Set0Row3[] = "\004\013 .\006\006"; static const char Ua1Set0Row3[] = "\004\014 .\006\006"; static const char Eng1Set1Row0[] = "QWERTYUIOP"; static const char Eng1Set1Row1[] = "ASDFGHJKL"; static const char Ru1Set1Row0[] = "ЙЦУКЕНГШЩЗХЪ"; static const char Ru1Set1Row1[] = "ФЫВАПРОЛДЖЭ"; static const char Ua1Set1Row0[] = "ЙЦУКЕНГШЩЗХЇ"; static const char Ua1Set1Row1[] = "ФІВАПРОЛДЖЄ"; static const char *Eng1Set0[] = { "qwertyuiop", "asdfghjkl", "\001zxcvbnm\005", Eng1Set0Row3, 0 }; static const char *Eng1Set1[] = { Eng1Set1Row0, Eng1Set1Row1, "\002ZXCVBNM\005", Eng1Set0Row3, 0 }; static const char *Eng1Set2[] = { Eng1Set1Row0, Eng1Set1Row1, "\003ZXCVBNM\005", Eng1Set0Row3, 0 }; static const char *Eng1Set3[] = { "+-*/", "@789", "\007456", "\010123", "\01100.", 0 }; static const char *Eng1Set4[] = { "#$%^&*()", "~`:;\"'{}", "<>?/\\|[]", "\011\004,! .@", 0 }; static const char *Rus1Set0[] = { "йцукенгшщзхъ", "фывапролджэ", "\015ячсмитьбю\005", Ru1Set0Row3, 0 }; static const char *Rus1Set1[] = { Ru1Set1Row0, Ru1Set1Row1, "\016ЯЧСМИТЬБЮ\005", Ru1Set0Row3, 0 }; static const char *Rus1Set2[] = { Ru1Set1Row0, Ru1Set1Row1, "\017ЯЧСМИТЬБЮ\005", Ru1Set0Row3, 0 }; static const char *Ukr1Set0[] = { "йцукенгшщзхї", "фівапролджє", "\020ячсмитьбюґ\005", Ua1Set0Row3, 0 }; static const char *Ukr1Set1[] = { Ua1Set1Row0, Ua1Set1Row1, "\021ЯЧСМИТЬБЮҐ\005", Ua1Set0Row3, 0 }; static const char *Ukr1Set2[] = { Ua1Set1Row0, Ua1Set1Row1, "\022ЯЧСМИТЬБЮҐ\005", Ua1Set0Row3, 0 }; static const GVKeySet Eng1Sets[] = { Eng1Set0, Eng1Set1, Eng1Set2, Eng1Set3, Eng1Set4, Rus1Set0, Rus1Set1, Rus1Set2, Ukr1Set0, Ukr1Set1, Ukr1Set2, 0 }; const GVKeyTable VirtualKeyboard_English1 = { Eng1SKeys, Eng1Sets }; #endif // GWIN_NEED_KEYBOARD_ENGLISH1
  3. Hello, I was able to rework the character removal method, it now works with both Cyrillic and English. The modified file is located at ugfx/src/gwin/gwin_textedit.c The method that needs to be modified is on line 30 called TextEditRemoveChar. The content of the code itself: static void TextEditRemoveChar(GHandle gh) { char *p; const char *q; unsigned sz, pos, charStart; if (!gh || !gh2obj->w.text) return; sz = strlen(gh2obj->w.text); pos = gh2obj->cursorPos; if (pos > sz) pos = gh2obj->cursorPos = sz; // Определяем начало символа в UTF-8 charStart = pos; while (charStart > 0 && (gh2obj->w.text[charStart] & 0xC0) == 0x80) { charStart--; } // Проверка, является ли символ многобайтовым (UTF-8) int isMultibyte = (gh2obj->w.text[charStart] & 0x80) != 0; q = gh2obj->w.text + pos; if (!(gh->flags & GWIN_FLG_ALLOCTXT)) { // Выделяем память и копируем строку if (!(p = gfxAlloc(sz))) return; if (isMultibyte) { // Удаление многобайтового символа memcpy(p, gh2obj->w.text, charStart); memcpy(p + charStart, q + (pos - charStart), sz - pos); } else { // Удаление однобайтового символа memcpy(p, gh2obj->w.text, pos); memcpy(p + pos, q + 1, sz - pos); } gh->flags |= GWIN_FLG_ALLOCTXT; } else { if (isMultibyte) { // Удаление многобайтового символа с сдвигом memmove((char *)gh2obj->w.text + charStart, q + (pos - charStart), sz - pos); p = gfxRealloc((char *)gh2obj->w.text, sz + 1, sz - (pos - charStart) + 1); } else { // Удаление однобайтового символа с сдвигом memmove((char *)q, q + 1, sz - pos); p = gfxRealloc((char *)gh2obj->w.text, sz + 1, sz); } if (!p) return; } gh2obj->w.text = p; gh2obj->cursorPos = charStart; // Перемещаем курсор }
  4. Hello again, yes I was able to figure out what was wrong thanks to Sergei. But now there is another problem, when deleting Cyrillic characters (and we know that the Cyrillic character is two bytes of memory) the programme deletes not completely the character (i.e. one byte). How can this be cured? I will be grateful for your help! #include "gfx.h" #include "/home/office-nivki/Documents/projects/resources/ugfx/src/gwin/gwin_keyboard_layout.h" static const GVSpecialKey Eng1SKeys[] = { { "\001", 0, GVKEY_SINGLESET, 1 }, // \001 (1) = Shift Lower to Upper { "\001", 0, GVKEY_INVERT|GVKEY_LOCKSET, 2 }, // \002 (2) = Shift Upper to Upper Lock { "\002", 0, GVKEY_INVERT|GVKEY_LOCKSET, 0 }, // \003 (3) = Shift Upper Lock to Lower { "123", 0, GVKEY_LOCKSET, 3 }, // \004 (4) = Change to Numbers { "\010", "\b", 0, 0 }, // \005 (5) = Backspace { "\015", "\r", 0, 0 }, // \006 (6) = Enter 1 { "\015", "\r", 0, 0 }, // \007 (7) = Enter 2 (Short keycap) { "Sym", 0, GVKEY_LOCKSET, 4 }, // \010 (8) = Change to Symbols { "aA", 0, GVKEY_LOCKSET, 0 }, // \011 (9) = Change to Lower Alpha { "RU", 0, GVKEY_LOCKSET, 5 }, // \012 (10) = Change to Lower Alpha { "EN", 0, GVKEY_LOCKSET, 0 }, // \013 (11) = Change to Lower Alpha { "\001", 0, GVKEY_SINGLESET, 6 }, // \014 (12) = Shift Lower to Upper { "\001", 0, GVKEY_INVERT|GVKEY_LOCKSET, 7 }, // \015 (13) = Shift Upper to Upper Lock { "\002", 0, GVKEY_INVERT|GVKEY_LOCKSET, 5 }, // \016 (14) = Shift Upper Lock to Lower }; static const char Eng1Set0Row3[] = "\004\012 .\006\006"; static const char Ru1Set0Row3[] = "\004\004\013 .\006\006"; static const char Eng1Set1Row0[] = "QWERTYUIOP"; static const char Eng1Set1Row1[] = "ASDFGHJKL"; static const char Ru1Set1Row0[] = "ЙЦУКЕНГШЩЗХЪ"; static const char Ru1Set1Row1[] = "ФЫВАПРОЛДЖЭ"; static const char *Eng1Set0[] = { "qwertyuiop", "asdfghjkl", "\001zxcvbnm\005", Eng1Set0Row3, 0 }; static const char *Eng1Set1[] = { Eng1Set1Row0, Eng1Set1Row1, "\002ZXCVBNM\005", Eng1Set0Row3, 0 }; static const char *Eng1Set2[] = { Eng1Set1Row0, Eng1Set1Row1, "\003ZXCVBNM\005", Eng1Set0Row3, 0 }; static const char *Eng1Set3[] = { "+-*/", "@789", "\007456", "\010123", "\01100.", 0 }; static const char *Eng1Set4[] = { "#$%^&*()", "~`:;\"'{}", "<>?/\\|[]", "\011\004,! .@", 0 }; static const char *Rus1Set0[] = { "йцукенгшщзхъ", "фывапролджэ", "\014ячсмитьбю\005", Ru1Set0Row3, 0 }; static const char *Rus1Set1[] = { Ru1Set1Row0, Ru1Set1Row1, "\015ЯЧСМИТЬБЮ\005", Ru1Set0Row3, 0 }; static const char *Rus1Set2[] = { Ru1Set1Row0, Ru1Set1Row1, "\016ЯЧСМИТЬБЮ\005", Ru1Set0Row3, 0 }; static const GVKeySet Eng1Sets[] = { Eng1Set0, Eng1Set1, Eng1Set2, Eng1Set3, Eng1Set4, Rus1Set0, Rus1Set1, Rus1Set2, 0 }; const GVKeyTable VirtualKeyboard_EnRu1 = { Eng1SKeys, Eng1Sets }; static GListener gl; static GHandle ghTextedit1; static GHandle ghTextedit2; static GHandle ghTextedit3; static GHandle KeyboardNum; static void guiCreate(void) { GWidgetInit wi; gwinWidgetClearInit(&wi); // TextEdit1 wi.g.show = gTrue; wi.g.x = 10; wi.g.y = 20; wi.g.width = 200; wi.g.height = 35; wi.text = "Use the TAB key"; ghTextedit1 = gwinTexteditCreate(0, &wi, 100); // TextEdit2 wi.g.show = gTrue; wi.g.x = 10; wi.g.y = 100; wi.g.width = 200; wi.g.height = 35; wi.text = "to switch between"; ghTextedit2 = gwinTexteditCreate(0, &wi, 20); // TextEdit3 wi.g.show = gTrue; wi.g.x = 10; wi.g.y = 180; wi.g.width = 200; wi.g.height = 35; wi.text = "the different widgets"; ghTextedit3 = gwinTexteditCreate(0, &wi, 100); // Virtual keyboard wi.g.show = gTrue; wi.g.x = 0; wi.g.y = (gdispGetHeight()/2); wi.g.width = gdispGetWidth(); wi.g.height = gdispGetHeight()/2; wi.text = "KeybNum"; KeyboardNum = gwinKeyboardCreate(0, &wi); gwinKeyboardSetLayout(KeyboardNum, &VirtualKeyboard_EnRu1); // We also want to listen to keyboard events from the virtual keyboard geventAttachSource(&gl, gwinKeyboardGetEventSource(KeyboardNum), GLISTEN_KEYTRANSITIONS|GLISTEN_KEYUP); } int main(void) { gfxInit(); gdispClear(GFX_SILVER); gwinSetDefaultFont(gdispOpenFont("MontserratRegular16")); gwinSetDefaultStyle(&WhiteWidgetStyle, gFalse); gwinSetDefaultColor(GFX_BLACK); gwinSetDefaultBgColor(GFX_WHITE); geventListenerInit(&gl); geventAttachSource(&gl, ginputGetKeyboard(0), 0); guiCreate(); while(1) { gfxSleepMilliseconds(500); } }
  5. Excuse me, but could you tell me how to use your code (i.e. as I understand I need to modify the file gwin_keyboard_layout.c by adding your code there). I would like to know how you use it in your programme, I used as a test the sample file, which is in the library itself. Would you mind showing me a piece of code with the application?
  6. This is an example I've made, but it doesn't compile and I don't understand what's wrong. Can you please look at what I'm doing wrong? #include "gfx.h" // Визначення російської розкладки клавіатури static const GVSpecialKey RussianKeys[] = { { "\001", 0, GVKEY_SINGLESET, 1 }, // Shift: строчні -> заглавні { "\002", 0, GVKEY_INVERT|GVKEY_LOCKSET, 0 }, // Shift: заглавні -> строчні { "123", 0, GVKEY_LOCKSET, 2 }, // Перехід на цифри { "\010", "\b", 0, 0 }, // Backspace { "\015", "\r", 0, 0 }, // Enter { "Sym", 0, GVKEY_LOCKSET, 3 }, // Перехід на символи }; static const char RussianSet0Row0[] = "йцукенгшщзхъ"; static const char RussianSet0Row1[] = "фывапролджэ"; static const char RussianSet0Row2[] = "ячсмитьбю"; static const char *RussianSet0[] = { RussianSet0Row0, RussianSet0Row1, RussianSet0Row2, "\004", 0 }; static const char RussianSet1Row0[] = "ЙЦУКЕНГШЩЗХЪ"; static const char RussianSet1Row1[] = "ФЫВАПРОЛДЖЭ"; static const char RussianSet1Row2[] = "ЯЧСМИТЬБЮ"; static const char *RussianSet1[] = { RussianSet1Row0, RussianSet1Row1, RussianSet1Row2, "\004", 0 }; static const char *RussianSet2[] = { "123", "456", "789", "0.+-", 0 }; static const char *RussianSet3[] = { "!@#$%^&*()", "<>?:\"{}", "[];'\\|", ",./~`", 0 }; static const GVKeySet RussianKeySets[] = { RussianSet0, RussianSet1, RussianSet2, RussianSet3, 0 }; // Об'єднуємо всі набори в одну таблицю const GVKeyTable RussianKeyboardLayout = { RussianKeys, RussianKeySets }; static GHandle ghConsole; static GHandle ghTextedit1; static GHandle ghTextedit2; static GHandle ghTextedit3; static GListener gl; static GHandle ghKeyboard; static void guiCreate(void) { GWidgetInit wi; gwinWidgetClearInit(&wi); // Console wi.g.show = gTrue; wi.g.x = 0; wi.g.y = 0; wi.g.width = gdispGetWidth() / 2; wi.g.height = gdispGetHeight(); ghConsole = gwinConsoleCreate(0, &wi.g); gwinSetColor(ghConsole, GFX_YELLOW); gwinSetBgColor(ghConsole, GFX_BLACK); gwinSetFont(ghConsole, gdispOpenFont("UI2")); gwinClear(ghConsole); // TextEdit1 wi.g.show = gTrue; wi.g.x = gdispGetWidth() / 2 + 10; wi.g.y = 20; wi.g.width = 200; wi.g.height = 35; wi.text = "Use the TAB key"; ghTextedit1 = gwinTexteditCreate(0, &wi, 100); // TextEdit2 wi.g.show = gTrue; wi.g.x = gdispGetWidth() / 2 + 10; wi.g.y = 100; wi.g.width = 200; wi.g.height = 35; wi.text = "to switch between"; ghTextedit2 = gwinTexteditCreate(0, &wi, 20); // TextEdit3 wi.g.show = gTrue; wi.g.x = gdispGetWidth() / 2 + 10; wi.g.y = 180; wi.g.width = 200; wi.g.height = 35; wi.text = "the different widgets"; ghTextedit3 = gwinTexteditCreate(0, &wi, 100); // Virtual keyboard wi.g.show = gTrue; wi.g.x = 0; wi.g.y = gdispGetHeight() * 3 / 4; wi.g.width = gdispGetWidth(); wi.g.height = gdispGetHeight() / 4; ghKeyboard = gwinKeyboardCreate(0, &wi); // Встановлюємо власну розкладку gwinKeyboardSetLayout(ghKeyboard, &RussianKeyboardLayout); } int main(void) { GEventKeyboard* pk; unsigned i; gfxInit(); gdispClear(GFX_SILVER); gwinSetDefaultFont(gdispOpenFont("DejaVuSans16")); gwinSetDefaultStyle(&WhiteWidgetStyle, gFalse); gwinSetDefaultColor(GFX_BLACK); gwinSetDefaultBgColor(GFX_WHITE); geventListenerInit(&gl); geventAttachSource(&gl, ginputGetKeyboard(0), GLISTEN_KEYTRANSITIONS | GLISTEN_KEYUP); guiCreate(); gwinPrintf(ghConsole, "Russian Keyboard Monitor...\n"); while (1) { // Get an Event pk = (GEventKeyboard*)geventEventWait(&gl, gDelayForever); if (pk->type != GEVENT_KEYBOARD) continue; gwinPrintf(ghConsole, "KEYSTATE: 0x%04X [ %s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s]", pk->keystate, (!pk->keystate ? "NONE " : ""), ((pk->keystate & GKEYSTATE_KEYUP) ? "KEYUP " : ""), ((pk->keystate & GKEYSTATE_REPEAT) ? "REPEAT " : ""), ((pk->keystate & GKEYSTATE_SPECIAL) ? "SPECIAL " : ""), ((pk->keystate & GKEYSTATE_RAW) ? "RAW " : ""), ((pk->keystate & GKEYSTATE_SHIFT_L) ? "LSHIFT " : ""), ((pk->keystate & GKEYSTATE_SHIFT_R) ? "RSHIFT " : ""), ((pk->keystate & GKEYSTATE_CTRL_L) ? "LCTRL " : ""), ((pk->keystate & GKEYSTATE_CTRL_R) ? "RCTRL " : ""), ((pk->keystate & GKEYSTATE_ALT_L) ? "LALT " : ""), ((pk->keystate & GKEYSTATE_ALT_R) ? "RALT " : ""), ((pk->keystate & GKEYSTATE_FN) ? "FN " : ""), ((pk->keystate & GKEYSTATE_COMPOSE) ? "COMPOSE " : ""), ((pk->keystate & GKEYSTATE_WINKEY) ? "WINKEY " : ""), ((pk->keystate & GKEYSTATE_CAPSLOCK) ? "CAPSLOCK " : ""), ((pk->keystate & GKEYSTATE_NUMLOCK) ? "NUMLOCK " : ""), ((pk->keystate & GKEYSTATE_SCROLLLOCK) ? "SCROLLLOCK " : "") ); if (pk->bytecount) { gwinPrintf(ghConsole, " Keys:"); for (i = 0; i < pk->bytecount; i++) gwinPrintf(ghConsole, " 0x%02X", (int)(gU8)pk->c[i]); gwinPrintf(ghConsole, " ["); for (i = 0; i < pk->bytecount; i++) gwinPrintf(ghConsole, "%c", pk->c[i] >= ' ' && pk->c[i] <= '~' ? pk->c[i] : ' '); gwinPrintf(ghConsole, "]"); } gwinPrintf(ghConsole, "\n"); } }
  7. I would like to know if there is such an option to change the on-screen keyboard layout language? I would like to change it to my own language. If so, do I need to change the library files? Could you please tell me how to do it?
×
×
  • Create New...