forked from Mirror/GodMode9
Add Unicode hex input
This commit is contained in:
parent
830479f50c
commit
942e67e507
@ -3,6 +3,7 @@
|
|||||||
#include "swkbd.h"
|
#include "swkbd.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
#include "hid.h"
|
#include "hid.h"
|
||||||
|
#include "utf.h"
|
||||||
|
|
||||||
|
|
||||||
static inline char to_uppercase(char c) {
|
static inline char to_uppercase(char c) {
|
||||||
@ -332,6 +333,30 @@ bool ShowKeyboard(char* inputstr, const u32 max_size, const char *format, ...) {
|
|||||||
} else if (key == KEY_SWITCH) {
|
} else if (key == KEY_SWITCH) {
|
||||||
ClearScreen(BOT_SCREEN, COLOR_STD_BG);
|
ClearScreen(BOT_SCREEN, COLOR_STD_BG);
|
||||||
return ShowStringPrompt(inputstr, max_size, str);
|
return ShowStringPrompt(inputstr, max_size, str);
|
||||||
|
} else if (key == KEY_UNICODE) {
|
||||||
|
if (cursor > 3 && cursor <= inputstr_size) {
|
||||||
|
u16 codepoint = 0;
|
||||||
|
for (char *c = inputstr + cursor - 4; c < inputstr + cursor; c++) {
|
||||||
|
if ((*c >= '0' && *c <= '9') || (*c >= 'A' && *c <= 'F') || (*c >= 'a' && *c <= 'f')) {
|
||||||
|
codepoint <<= 4;
|
||||||
|
codepoint |= *c - (*c <= '9' ? '0' : ((*c <= 'F' ? 'A' : 'a') - 10));
|
||||||
|
} else {
|
||||||
|
codepoint = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(codepoint != 0) {
|
||||||
|
char character[5] = {0};
|
||||||
|
u16 input[2] = {codepoint, 0};
|
||||||
|
utf16_to_utf8((u8*)character, input, 4, 1);
|
||||||
|
|
||||||
|
u32 char_size = GetCharSize(character);
|
||||||
|
memmove(inputstr + cursor - 4 + char_size, inputstr + cursor, max_size - cursor + 4 - char_size);
|
||||||
|
memcpy(inputstr + cursor - 4, character, char_size);
|
||||||
|
cursor -= 4 - char_size;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else if (key && (key < 0x80)) {
|
} else if (key && (key < 0x80)) {
|
||||||
if ((cursor < (max_size-1)) && (inputstr_size < max_size)) {
|
if ((cursor < (max_size-1)) && (inputstr_size < max_size)) {
|
||||||
// pad string (if cursor beyound string size)
|
// pad string (if cursor beyound string size)
|
||||||
|
@ -19,11 +19,12 @@ enum {
|
|||||||
KEY_RIGHT = 0x89,
|
KEY_RIGHT = 0x89,
|
||||||
KEY_ESCAPE = 0x8A,
|
KEY_ESCAPE = 0x8A,
|
||||||
KEY_SWITCH = 0x8B,
|
KEY_SWITCH = 0x8B,
|
||||||
|
KEY_UNICODE = 0x8C,
|
||||||
KEY_TXTBOX = 0xFF
|
KEY_TXTBOX = 0xFF
|
||||||
};
|
};
|
||||||
|
|
||||||
// special key strings
|
// special key strings
|
||||||
#define SWKBD_KEYSTR "", "DEL", "INS", "SUBMIT", "CAPS", "#$@", "123", "ABC", "←", "→", "ESC", "SWITCH"
|
#define SWKBD_KEYSTR "", "DEL", "INS", "SUBMIT", "CAPS", "#$@", "123", "ABC", "←", "→", "ESC", "SWITCH", "U+"
|
||||||
|
|
||||||
#define COLOR_SWKBD_NORMAL COLOR_GREY
|
#define COLOR_SWKBD_NORMAL COLOR_GREY
|
||||||
#define COLOR_SWKBD_PRESSED COLOR_LIGHTGREY
|
#define COLOR_SWKBD_PRESSED COLOR_LIGHTGREY
|
||||||
@ -56,7 +57,7 @@ enum {
|
|||||||
'4', '5', '6', 'D', 'C', \
|
'4', '5', '6', 'D', 'C', \
|
||||||
'3', '2', '1', 'B', 'A', \
|
'3', '2', '1', 'B', 'A', \
|
||||||
'0', '.', '_', KEY_LEFT, KEY_RIGHT, \
|
'0', '.', '_', KEY_LEFT, KEY_RIGHT, \
|
||||||
KEY_ALPHA, ' ', KEY_BKSPC
|
KEY_ALPHA, KEY_UNICODE, ' ', KEY_BKSPC
|
||||||
|
|
||||||
// offset, num of keys in row, width of special keys (...), 0
|
// offset, num of keys in row, width of special keys (...), 0
|
||||||
#define SWKBD_LAYOUT_ALPHABET \
|
#define SWKBD_LAYOUT_ALPHABET \
|
||||||
@ -80,7 +81,7 @@ enum {
|
|||||||
5, 0, \
|
5, 0, \
|
||||||
5, 0, \
|
5, 0, \
|
||||||
5, 18, 18, 0, \
|
5, 18, 18, 0, \
|
||||||
3, 30, 34, 30, 0, \
|
4, 20, 20, 31, 20, 0, \
|
||||||
0
|
0
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user