int main(int argc, string argv[]) { if (argc != 2) { invalid_key(); return 1; } int k = atoi(argv[1]); string message = get_message(); for (int i = 0, n = strlen(message); i < n; i++) { int result = (message[i] + k); int hold = k % 26; if (message[i] >= 'a' && message[i] <= 'z') { int checking = message[i] + hold; if (checking > 122) { message[i] = (checking - 122) + 96; printf("%c", message[i]); } else { printf("%c", checking); } } else if (message[i] >= 'A' && message[i] <= 'Z') { if (result > 90) { message[i] = (result - 90) + 64; printf("%c", message[i]); } else { message[i] = result; printf("%c", message[i]); } } else { printf("%c", message[i]); } } printf("\n"); }
void checkQKeySequence() { // Check that the valid keycode Qt::Key_unknown is handled gracefully // // Qt::Key_unknown is a valid Qt Key. But toString makes unicode gibberish // from it. '???'. // Reported with patch - mjansen QKeySequence unknown_key(Qt::Key_unknown); // The keycode falls into the unicode handling QString p = QChar((Qt::Key_unknown-0x10000)/0x400+0xd800); p += QChar((Qt::Key_unknown-0x10000)%400+0xdc00); QCOMPARE(unknown_key.toString(), p); // What happens QEXPECT_FAIL("", "Qt::Key_unknown not handled", Continue); QCOMPARE(unknown_key.toString(), QString()); // What i would expect // Check that the keycode -1 is handled gracefully. // // -1 happens for some keys when listening to keyPressEvent in QWidget::event() // It means the key is not supported by Qt. It probably should be // Qt::Key_unknown instead. Unsupported keys: (Alt+Print for example). // Reported with patch - mjansen QKeySequence invalid_key(-1); // The keycode falls into the handling of keys lesser that Key_escape QString p1 = QChar((-1) & 0xffff).toUpper(); QCOMPARE(invalid_key.toString(), QString("Meta+Ctrl+Alt+Shift+"+p1)); // What happens QEXPECT_FAIL("", "-1 not handled", Continue); QCOMPARE(invalid_key.toString(), QString()); // What i would expect // The famous "KDE4 eats my E key" bug: Win+E isn't parsed anymore. QKeySequence seq("Win+E"); QEXPECT_FAIL("", "Qt Bug 205255/134941 - QKeySequence silently discards unknown key modifiers", Continue); QVERIFY(seq.isEmpty()); // And what really happens QCOMPARE(seq.toString(), QLatin1String("E")); // KDE3 -> KDE4 migration. KDE3 used xKeycodeToKeysym or something and // stored the result QKeySequence seq2("Meta+Alt+Period"); QEXPECT_FAIL("", "Qt Bug 205255/134941 - QKeySequence silently discards unknown key modifiers", Continue); QVERIFY(seq2.isEmpty()); // And what really happens QCOMPARE(seq2.toString(), QLatin1String("Meta+Alt+")); }
void keyval_normalize (keys_perform_transfer & k) { if (invalid_key(k.kpt_bpm_up)) k.kpt_bpm_up = SEQ64_apostrophe; /* ' */ if (invalid_key(k.kpt_bpm_dn)) k.kpt_bpm_dn = SEQ64_semicolon; /* ; */ if (invalid_key(k.kpt_replace)) k.kpt_replace = SEQ64_Control_L; /* Ctrl-L */ if (invalid_key(k.kpt_queue)) k.kpt_queue = SEQ64_KP_Divide; /* Keypad-/ */ if (invalid_key(k.kpt_keep_queue)) k.kpt_keep_queue = SEQ64_backslash; /* \ */ if (invalid_key(k.kpt_snapshot_1)) k.kpt_snapshot_1 = SEQ64_Alt_L; /* Alt-L */ if (invalid_key(k.kpt_snapshot_2)) k.kpt_snapshot_2 = SEQ64_Alt_R; /* Alt-R */ if (invalid_key(k.kpt_screenset_up)) k.kpt_screenset_up = SEQ64_bracketright; /* ] */ if (invalid_key(k.kpt_screenset_dn)) k.kpt_screenset_dn = SEQ64_bracketright; /* [ */ if (invalid_key(k.kpt_set_playing_screenset)) k.kpt_set_playing_screenset = SEQ64_Home; /* Home */ if (invalid_key(k.kpt_group_on)) k.kpt_group_on = SEQ64_igrave; /* ` */ /* * TODO: fix this redundancy */ if (invalid_key(k.kpt_group_off)) k.kpt_group_off = SEQ64_apostrophe; /* bpm up!! */ if (invalid_key(k.kpt_group_learn)) k.kpt_group_learn = SEQ64_Insert; /* Insert */ if (invalid_key(k.kpt_start)) k.kpt_start = SEQ64_space; /* ' ' */ if (invalid_key(k.kpt_pause)) k.kpt_pause = SEQ64_period; /* . */ if (invalid_key(k.kpt_song_mode)) k.kpt_song_mode = SEQ64_F1; if (invalid_key(k.kpt_toggle_jack)) k.kpt_toggle_jack = SEQ64_F2; if (invalid_key(k.kpt_menu_mode)) k.kpt_menu_mode = SEQ64_F3; if (invalid_key(k.kpt_follow_transport)) k.kpt_follow_transport = SEQ64_F4; if (invalid_key(k.kpt_rewind)) k.kpt_rewind = SEQ64_F5; if (invalid_key(k.kpt_fast_forward)) k.kpt_fast_forward = SEQ64_F6; if (invalid_key(k.kpt_pointer_position)) k.kpt_pointer_position = SEQ64_F7; if (invalid_key(k.kpt_toggle_mutes)) k.kpt_toggle_mutes = SEQ64_F8; if (invalid_key(k.kpt_tap_bpm)) k.kpt_tap_bpm = SEQ64_F9; if (invalid_key(k.kpt_pattern_edit)) k.kpt_pattern_edit = SEQ64_equal; /* = */ if (invalid_key(k.kpt_event_edit)) k.kpt_event_edit = SEQ64_minus; /* - */ if (invalid_key(k.kpt_stop)) k.kpt_stop = SEQ64_Escape; /* Escape */ }