git-svn-id: svn://db.shs.com.ru/pip@173 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5

This commit is contained in:
2016-01-28 09:33:41 +00:00
parent b8a7fdfb23
commit 2ca12f0666

View File

@@ -48,48 +48,75 @@ PIKbdListener * PIKbdListener::_object = 0;
struct EscSeq { struct EscSeq {
const char * seq; const char * seq;
int key; int key;
int mod;
// 1 - shift
// 2 - alt
// 4 - ctrl
}; };
// unix
const EscSeq esc_seq[] = { const EscSeq esc_seq[] = {
// Linux {"[1A", PIKbdListener::UpArrow, 0},
{"[A", PIKbdListener::UpArrow}, {"[A", PIKbdListener::UpArrow, 0},
{"[1A", PIKbdListener::UpArrow}, {"OA", PIKbdListener::UpArrow, 4},
{"[B", PIKbdListener::DownArrow}, {"[1B", PIKbdListener::DownArrow, 0},
{"[1B", PIKbdListener::DownArrow}, {"[B", PIKbdListener::DownArrow, 0},
{"[C", PIKbdListener::RightArrow}, {"OB", PIKbdListener::DownArrow, 4},
{"[1C", PIKbdListener::RightArrow}, {"[1C", PIKbdListener::RightArrow, 0},
{"[D", PIKbdListener::LeftArrow}, {"[C", PIKbdListener::RightArrow, 0},
{"[1D", PIKbdListener::LeftArrow}, {"OC", PIKbdListener::RightArrow, 4},
{"[H", PIKbdListener::Home}, {"[1D", PIKbdListener::LeftArrow, 0},
{"[1H", PIKbdListener::Home}, {"[D", PIKbdListener::LeftArrow, 0},
{"[1~", PIKbdListener::Home}, {"OD", PIKbdListener::LeftArrow, 0},
{"[F", PIKbdListener::End}, {"[H", PIKbdListener::Home, 0},
{"[1F", PIKbdListener::End}, {"[1H", PIKbdListener::Home, 0},
{"[4~", PIKbdListener::End}, {"[1~", PIKbdListener::Home, 0},
{"[2~", PIKbdListener::Insert}, {"[F", PIKbdListener::End, 0},
{"[3~", PIKbdListener::Delete}, {"[1F", PIKbdListener::End, 0},
{"[5~", PIKbdListener::PageUp}, {"[4~", PIKbdListener::End, 0},
{"[6~", PIKbdListener::PageDown}, {"[2~", PIKbdListener::Insert, 0},
{"OP", PIKbdListener::F1}, {"[3~", PIKbdListener::Delete, 0},
{"[[A", PIKbdListener::F1}, {"[5~", PIKbdListener::PageUp, 0},
{"OQ", PIKbdListener::F2}, {"[6~", PIKbdListener::PageDown, 0},
{"[[B", PIKbdListener::F2}, {"[Z", PIKbdListener::Tab, 1},
{"OR", PIKbdListener::F3}, {"OP", PIKbdListener::F1, 0},
{"[[C", PIKbdListener::F3}, {"[[A", PIKbdListener::F1, 0},
{"OS", PIKbdListener::F4}, {"[11~", PIKbdListener::F1, 0},
{"[[D", PIKbdListener::F4}, {"OQ", PIKbdListener::F2, 0},
{"[[E", PIKbdListener::F5}, {"[[B", PIKbdListener::F2, 0},
{"[15~", PIKbdListener::F5}, {"[12~", PIKbdListener::F2, 0},
{"[17~", PIKbdListener::F6}, {"OR", PIKbdListener::F3, 0},
{"[18~", PIKbdListener::F7}, {"[[C", PIKbdListener::F3, 0},
{"[19~", PIKbdListener::F8}, {"[13~", PIKbdListener::F3, 0},
{"[20~", PIKbdListener::F9}, {"[25~", PIKbdListener::F3, 1},
{"[21~", PIKbdListener::F10}, {"OS", PIKbdListener::F4, 0},
{"[23~", PIKbdListener::F11}, {"[[D", PIKbdListener::F4, 0},
{"[24~", PIKbdListener::F12}, {"[14~", PIKbdListener::F4, 0},
{"[26~", PIKbdListener::F4, 1},
{"[[E", PIKbdListener::F5, 0},
{"OT", PIKbdListener::F5, 0},
{"[15~", PIKbdListener::F5, 0},
{"[28~", PIKbdListener::F5, 1},
{"OU", PIKbdListener::F6, 0},
{"[17~", PIKbdListener::F6, 0},
{"[29~", PIKbdListener::F6, 1},
{"OV", PIKbdListener::F7, 0},
{"[18~", PIKbdListener::F7, 0},
{"[31~", PIKbdListener::F7, 1},
{"OW", PIKbdListener::F8, 0},
{"[19~", PIKbdListener::F8, 0},
{"[32~", PIKbdListener::F8, 1},
{"OX", PIKbdListener::F9, 0},
{"[20~", PIKbdListener::F9, 0},
{"[33~", PIKbdListener::F9, 1},
{"OY", PIKbdListener::F10 0},
{"[21~", PIKbdListener::F10 0},
{"[34~", PIKbdListener::F10 1},
{"OZ", PIKbdListener::F11 0},
{"[23~", PIKbdListener::F11 0},
{"O[", PIKbdListener::F12 0},
{"[24~", PIKbdListener::F12 0},
// End // End
{0, 0}, {0, 0, 0},
}; };
#endif #endif
@@ -231,11 +258,20 @@ void PIKbdListener::readKeyboard() {
// 4 - alt+shift 3 // 4 - alt+shift 3
// 5 - ctrl 4 // 5 - ctrl 4
// 8 - ctrl+alt+shift 7 // 8 - ctrl+alt+shift 7
if (rc[0] == '\e' && ret >= 2) { // escape-seq if (rc[0] == '\e') {
if (ret == 2) {
mod = 2;
ke.key = PIChar::fromConsole(rc[1]).unicode16Code();
} else {// escape-seq
if (rc[1] == '\e') { // search for Alt
for (int i = 1; i < 7; ++i) rc[i] = rc[i + 1];
mod = 2;
ret--;
}
if (rc[1] == '[') { if (rc[1] == '[') {
for (int i = 2; i < 7; ++i) // search for modifier for (int i = 2; i < 7; ++i) // search for modifier
if (rc[i] == ';') { if (rc[i] == ';') {
mod = rc[i + 1] - '0' - 1; mod |= rc[i + 1] - '0' - 1;
for (int j = i; j < 6; ++j) rc[j] = rc[j + 2]; for (int j = i; j < 6; ++j) rc[j] = rc[j + 2];
rc[6] = rc[7] = 0; rc[6] = rc[7] = 0;
ret -= 2; ret -= 2;
@@ -244,10 +280,19 @@ void PIKbdListener::readKeyboard() {
} }
if (ret >= 3 && rc[1] == 'O') { // search for modifier (F1-F4) if (ret >= 3 && rc[1] == 'O') { // search for modifier (F1-F4)
if (rc[2] >= '1' && rc[2] <= '8') { if (rc[2] >= '1' && rc[2] <= '8') {
mod = rc[2] - '0' - 1; mod |= rc[2] - '0' - 1;
for (int j = 2; j < 6; ++j) rc[j] = rc[j + 1]; for (int j = 2; j < 6; ++j) rc[j] = rc[j + 1];
rc[7] = 0; rc[7] = 0;
ret -= 1; ret--;
}
}
for (int i = 0; ; ++i) {
if (!esc_seq[i].seq) break;
if (strcmp(esc_seq[i].seq, &(rc[1])) == 0) {
ke.key = esc_seq[i].key;
mod |= esc_seq[i].mod;
break;
}
} }
} }
if (mod >= 0 && mod <= 15) { if (mod >= 0 && mod <= 15) {
@@ -259,15 +304,7 @@ void PIKbdListener::readKeyboard() {
/*cout << "wo mods (" << mod << ")\n"; /*cout << "wo mods (" << mod << ")\n";
for (int i = 0; i < ret; ++i) for (int i = 0; i < ret; ++i)
cout << "'" << (char)(rc[i]) << "' "; cout << "'" << (char)(rc[i]) << "' ";
cout << endl; cout << endl;*/
}*/
for (int i = 0; ; ++i) {
if (!esc_seq[i].seq) break;
if (strcmp(esc_seq[i].seq, &(rc[1])) == 0) {
ke.key = esc_seq[i].key;
break;
}
}
} }
if (ke.key == 0 && ret > 1) if (ke.key == 0 && ret > 1)
ke.key = PIChar(rc).unicode16Code(); ke.key = PIChar(rc).unicode16Code();