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