Vaisr Posted December 16, 2024 Report Posted December 16, 2024 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?
Joel Bodenmann Posted December 16, 2024 Report Posted December 16, 2024 Hello & Welcome to the µGFX community! This can be done by defining a custom keyboard layout and setting it via gwinKeyboardGetEventSource(). You can have a look at the built-in layout as a reference which you can find under src/gwin/gwin_keyboard_layout.c
Vaisr Posted January 27 Author Report Posted January 27 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"); } }
Sergey Kushnir Posted Sunday at 09:43 PM Report Posted Sunday at 09:43 PM /* * This file is subject to the terms of the GFX License. If a copy of * the license was not distributed with this file, you can obtain one at: * * http://ugfx.io/license.html */ #include "../../gfx.h" #if GFX_USE_GWIN && GWIN_NEED_KEYBOARD #include "gwin_keyboard_layout.h" #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 Alpha }; static const char Eng1Set0Row3[] = "\004 .\006\006"; static const char Eng1Set1Row0[] = "QWERTYUIOP"; static const char Eng1Set1Row1[] = "ASDFGHJKL"; 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 GVKeySet Eng1Sets[] = { Eng1Set0, Eng1Set1, Eng1Set2, Eng1Set3, Eng1Set4, 0 }; const GVKeyTable VirtualKeyboard_English1 = { Eng1SKeys, Eng1Sets }; #endif // GWIN_NEED_KEYBOARD_ENGLISH1 #if GWIN_NEED_KEYBOARD_EN_RU1 /* 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 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 }; #endif // GWIN_NEED_KEYBOARD_ENGLISH1 #if GWIN_NEED_KEYBOARD_NUM /* 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 NumSKeys[] = { { "\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 { "ESC", "\x1b", 0, 0 }, // \017 (15) = Escape }; static const char *NumSet3[] = { "789\017", "456-", "123\005", "00.\007", 0 }; static const GVKeySet NumSets[] = { NumSet3, 0 }; const GVKeyTable VirtualKeyboard_Num = { NumSKeys, NumSets }; #endif // GWIN_NEED_KEYBOARD_ENGLISH1 #endif // GFX_USE_GWIN && GWIN_NEED_KEYBOARD It is my code for keyboards
Vaisr Posted Sunday at 10:00 PM Author Report Posted Sunday at 10:00 PM 15 minutes ago, Sergey Kushnir said: /* * This file is subject to the terms of the GFX License. If a copy of * the license was not distributed with this file, you can obtain one at: * * http://ugfx.io/license.html */ #include "../../gfx.h" #if GFX_USE_GWIN && GWIN_NEED_KEYBOARD #include "gwin_keyboard_layout.h" #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 Alpha }; static const char Eng1Set0Row3[] = "\004 .\006\006"; static const char Eng1Set1Row0[] = "QWERTYUIOP"; static const char Eng1Set1Row1[] = "ASDFGHJKL"; 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 GVKeySet Eng1Sets[] = { Eng1Set0, Eng1Set1, Eng1Set2, Eng1Set3, Eng1Set4, 0 }; const GVKeyTable VirtualKeyboard_English1 = { Eng1SKeys, Eng1Sets }; #endif // GWIN_NEED_KEYBOARD_ENGLISH1 #if GWIN_NEED_KEYBOARD_EN_RU1 /* 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 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 }; #endif // GWIN_NEED_KEYBOARD_ENGLISH1 #if GWIN_NEED_KEYBOARD_NUM /* 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 NumSKeys[] = { { "\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 { "ESC", "\x1b", 0, 0 }, // \017 (15) = Escape }; static const char *NumSet3[] = { "789\017", "456-", "123\005", "00.\007", 0 }; static const GVKeySet NumSets[] = { NumSet3, 0 }; const GVKeyTable VirtualKeyboard_Num = { NumSKeys, NumSets }; #endif // GWIN_NEED_KEYBOARD_ENGLISH1 #endif // GFX_USE_GWIN && GWIN_NEED_KEYBOARD It is my code for keyboards 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?
Sergey Kushnir Posted Monday at 02:16 PM Report Posted Monday at 02:16 PM GHandle KeyboardNum; // Create the keyboard GWidgetInit wi; gwinWidgetClearInit(&wi); wi.g.show = gTrue; wi.g.x = 200; wi.g.y = 185; wi.g.width = 660; wi.g.height = 240; wi.text = "KeybNum"; KeyboardNum = gwinKeyboardCreate(0, &wi); gwinKeyboardSetLayout(KeyboardNum, &VirtualKeyboard_Num); gwinSetFont(KeyboardNum, dejavu_sans_con28); // We also want to listen to keyboard events from the virtual keyboard geventAttachSource(&glistener, gwinKeyboardGetEventSource(KeyboardNum), GLISTEN_KEYTRANSITIONS|GLISTEN_KEYUP);
Sergey Kushnir Posted Monday at 07:57 PM Report Posted Monday at 07:57 PM I found a piece of a code // Fonts font_t open_sans24,open_sans28; // Слушатель событий GListener glistener; GHandle ghKeyboard, ghConsole1; GEvent* pe; GEventKeyboard * pk; void guiCreate(void) { GWidgetInit wi; // Apply some default values for GWIN gwinWidgetClearInit(&wi); wi.g.show = TRUE; // Prepare fonts - #define GDISP_INCLUDE_FONT_DEJAVUSANSxx TRUE - reqd in gfxconf.h) open_sans24 = gdispOpenFont("open_sans24"); open_sans28 = gdispOpenFont("open_sans28"); // Создаем "слушателя" события geventListenerInit(&glistener); geventAttachSource(&glistener, ginputGetMouse(0), GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA); gwinAttachListener(&glistener); // Устанавливаем дефолтные стили GUI gwinSetDefaultFont(open_sans24);//DejaVuSans20 gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); // Create the keyboard wi.g.show = gTrue; wi.g.x = 0; wi.g.y = gdispGetHeight()/2; wi.g.width = gdispGetWidth(); wi.g.height = gdispGetHeight()/2; ghKeyboard = gwinKeyboardCreate(0, &wi); gwinKeyboardSetLayout(ghKeyboard, &VirtualKeyboard_EnRu1); gwinSetFont(ghKeyboard, open_sans28); // We also want to listen to keyboard events from the virtual keyboard geventAttachSource(&glistener, gwinKeyboardGetEventSource(ghKeyboard), GLISTEN_KEYTRANSITIONS|GLISTEN_KEYUP); // Create console widget: ghConsole1 wi.g.parent = ghPage1; wi.g.show = TRUE; wi.g.x = 300; wi.g.y = 2; wi.g.width = 700; wi.g.height = 290; wi.text = "Ready"; wi.customParam = 0; wi.customStyle = 0; ghConsole1 = gwinConsoleCreate(0, &wi.g); gwinSetFont(ghConsole1, dejavu_sans_12); gwinSetColor(ghConsole1, Black); gwinSetBgColor(ghConsole1, HTML2COLOR(0xd2d2d2)); gwinShow(ghConsole1); gwinClear(ghConsole1); } ...... while (1) { // Get an Event pe = geventEventWait(&glistener, 1000); switch(pe->type) { case GEVENT_GWIN_KEYBOARD: ///(GEVENT_GWIN_CTRL_FIRST+6) // This is a widget event generated on the standard gwin event source gwinPrintf(ghConsole1, "Keyboard visibility has changed\n"); break; case GEVENT_KEYBOARD: // This is a keyboard event from a keyboard source which must be separately listened to. // It is not sent on the gwin event source even though in this case it was generated by a gwin widget. pk = (GEventKeyboard *)pe; gwinPrintf(ghConsole1, "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(ghConsole1, " Keys:"); for (i = 0; i < pk->bytecount; i++) gwinPrintf(ghConsole1, " 0x%02X", (int)(gU8)pk->c[i]); gwinPrintf(ghConsole1, " ["); for (i = 0; i < pk->bytecount; i++) gwinPrintf(ghConsole1, "%c", pk->c[i] >= ' ' && pk->c[i] <= '~' ? pk->c[i] : ' '); gwinPrintf(ghConsole1, "]"); } gwinPrintf(ghConsole1, "\n"); break; } }
Joel Bodenmann Posted Monday at 09:33 PM Report Posted Monday at 09:33 PM On 27/01/2025 at 18:44, Vaisr said: 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? Could you provide some more details? I had no problems compiling the code. Did you forget the inclusion of gwin/gwin_keyboard_layout.h or enabling the options in gfxconf.h? Please share your full build output.
Vaisr Posted Thursday at 02:53 PM Author Report Posted Thursday at 02:53 PM 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! On 2/17/2025 at 9:57 PM, Sergey Kushnir said: I found a piece of a code // Fonts font_t open_sans24,open_sans28; // Слушатель событий GListener glistener; GHandle ghKeyboard, ghConsole1; GEvent* pe; GEventKeyboard * pk; void guiCreate(void) { GWidgetInit wi; // Apply some default values for GWIN gwinWidgetClearInit(&wi); wi.g.show = TRUE; // Prepare fonts - #define GDISP_INCLUDE_FONT_DEJAVUSANSxx TRUE - reqd in gfxconf.h) open_sans24 = gdispOpenFont("open_sans24"); open_sans28 = gdispOpenFont("open_sans28"); // Создаем "слушателя" события geventListenerInit(&glistener); geventAttachSource(&glistener, ginputGetMouse(0), GLISTEN_MOUSEDOWNMOVES|GLISTEN_MOUSEMETA); gwinAttachListener(&glistener); // Устанавливаем дефолтные стили GUI gwinSetDefaultFont(open_sans24);//DejaVuSans20 gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); // Create the keyboard wi.g.show = gTrue; wi.g.x = 0; wi.g.y = gdispGetHeight()/2; wi.g.width = gdispGetWidth(); wi.g.height = gdispGetHeight()/2; ghKeyboard = gwinKeyboardCreate(0, &wi); gwinKeyboardSetLayout(ghKeyboard, &VirtualKeyboard_EnRu1); gwinSetFont(ghKeyboard, open_sans28); // We also want to listen to keyboard events from the virtual keyboard geventAttachSource(&glistener, gwinKeyboardGetEventSource(ghKeyboard), GLISTEN_KEYTRANSITIONS|GLISTEN_KEYUP); // Create console widget: ghConsole1 wi.g.parent = ghPage1; wi.g.show = TRUE; wi.g.x = 300; wi.g.y = 2; wi.g.width = 700; wi.g.height = 290; wi.text = "Ready"; wi.customParam = 0; wi.customStyle = 0; ghConsole1 = gwinConsoleCreate(0, &wi.g); gwinSetFont(ghConsole1, dejavu_sans_12); gwinSetColor(ghConsole1, Black); gwinSetBgColor(ghConsole1, HTML2COLOR(0xd2d2d2)); gwinShow(ghConsole1); gwinClear(ghConsole1); } ...... while (1) { // Get an Event pe = geventEventWait(&glistener, 1000); switch(pe->type) { case GEVENT_GWIN_KEYBOARD: ///(GEVENT_GWIN_CTRL_FIRST+6) // This is a widget event generated on the standard gwin event source gwinPrintf(ghConsole1, "Keyboard visibility has changed\n"); break; case GEVENT_KEYBOARD: // This is a keyboard event from a keyboard source which must be separately listened to. // It is not sent on the gwin event source even though in this case it was generated by a gwin widget. pk = (GEventKeyboard *)pe; gwinPrintf(ghConsole1, "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(ghConsole1, " Keys:"); for (i = 0; i < pk->bytecount; i++) gwinPrintf(ghConsole1, " 0x%02X", (int)(gU8)pk->c[i]); gwinPrintf(ghConsole1, " ["); for (i = 0; i < pk->bytecount; i++) gwinPrintf(ghConsole1, "%c", pk->c[i] >= ' ' && pk->c[i] <= '~' ? pk->c[i] : ' '); gwinPrintf(ghConsole1, "]"); } gwinPrintf(ghConsole1, "\n"); break; } } On 2/17/2025 at 11:33 PM, Joel Bodenmann said: Could you provide some more details? I had no problems compiling the code. Did you forget the inclusion of gwin/gwin_keyboard_layout.h or enabling the options in gfxconf.h? Please share your full build output. #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); } }
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now