static int key_hook(int keycode, t_env *env) { debug_stdout("INIT", FILE_LINE_FUN); if (SCOP_DEBUG) fprintf(stdout, "keycode:%d\n", keycode); keycodes(env, keycode); debug_stdout("END", FILE_LINE_FUN); return (EXIT_SUCCESS); }
quint32 QxtGlobalShortcutPrivate::nativeKeycode(Qt::Key key) { quint32 native = 0; KeySym keysym = XStringToKeysym(QKeySequence(key).toString().toLatin1().data()); if (keysym == XCB_NO_SYMBOL) keysym = static_cast<ushort>(key); xcb_key_symbols_t *xcbKeySymbols = xcb_key_symbols_alloc(QX11Info::connection()); QScopedPointer<xcb_keycode_t, QScopedPointerPodDeleter> keycodes( xcb_key_symbols_get_keycode(xcbKeySymbols, keysym)); native = keycodes.data()[0]; // Use the first keycode xcb_key_symbols_free(xcbKeySymbols); return native; }
void process_command (void) { uint8_t num_tokens = tokenize_command(); if (num_tokens == 0) // no commands return; /* for (uint8_t i = 0; i < num_tokens; i++) { m_usb_tx_char ('\t'); for (char *ptr = command_tokens[i]; *ptr != '\0'; ptr++) m_usb_tx_char (*ptr); printf ("\n"); } */ if (strcmp (command_tokens[0], "help") == 0) printf ("Commands: ls, cd, print, mkdir, rmdir, write, append, edit, keycode\r\n"); else if (strcmp (command_tokens[0], "ls") == 0) { if (num_tokens > 1) printf ("ls does not take any arguments\r\n"); else ls(); } else if (strcmp (command_tokens[0], "cd") == 0) { if (num_tokens != 2) { printf ("cd requires one argument (the destination directory)\r\n"); return; } if (!m_sd_push (command_tokens[1])) printf ("error entering "); else printf ("now in "); for (char *c = command_tokens[1]; *c != '\0'; c++) putchar (*c); printf ("\r\n"); } else if (strcmp (command_tokens[0], "print") == 0) { if (num_tokens != 2) { printf ("print requires one argument (the file to print)\r\n"); return; } printFile (command_tokens[1]); } else if (strcmp (command_tokens[0], "mkdir") == 0) { if (num_tokens != 2) { printf ("mkdir requires one argument (the directory to create)\r\n"); return; } if (!m_sd_mkdir (command_tokens[1])) { printf ("error creating directory "); } else { printf ("successfully created directory "); m_sd_commit(); } for (char *c = command_tokens[1]; *c != '\0'; c++) putchar (*c); printf ("\r\n"); } else if (strcmp (command_tokens[0], "rmdir") == 0) { if (num_tokens != 2) { printf ("rmdir requires one argument (the directory to delete)\n"); return; } if (!m_sd_rmdir (command_tokens[1])) { printf ("error deleting directory "); } else { printf ("successfully deleted directory "); m_sd_commit(); } for (char *c = command_tokens[1]; *c != '\0'; c++) putchar (*c); printf ("\r\n"); } else if (strcmp (command_tokens[0], "write") == 0) { if (num_tokens < 3) { printf ("write requires a filename, followed by the data to write\r\n"); return; } writeToFile (command_tokens[1], CREATE_FILE, command_ptr - command_tokens[2], (uint8_t*)command_tokens[2]); } else if (strcmp (command_tokens[0], "append") == 0) { if (num_tokens < 3) { printf ("append requires a filename, followed by the data to write\r\n"); return; } writeToFile (command_tokens[1], APPEND_FILE, command_ptr - command_tokens[2], (uint8_t*)command_tokens[2]); } else if (strcmp (command_tokens[0], "edit") == 0) { if (num_tokens < 2) { printf ("edit requires a filename\r\n"); return; } uint8_t fid = 255; if (!m_sd_open_file (command_tokens[1], APPEND_FILE, &fid)) { // if opening the file in r/w mode failed if (m_sd_error_code == ERROR_FAT32_NOT_FOUND) { // if the reason was because the file doesn't exist, try creating it m_sd_open_file (command_tokens[1], CREATE_FILE, &fid); } } if (fid == 255) { // the file is still not open printf ("Couldn't open/create file "); for (char *c = command_tokens[1]; *c != '\0'; c++) putchar (*c); printf ("\r\n"); return; } edit (fid, command_tokens[1]); if (!m_sd_close_file (fid)) { printf ("Error closing file! Error code %d\r\n", m_sd_error_code); } } else if (strcmp (command_tokens[0], "keycode") == 0) { // print the ASCII number of the pressed keys, CTRL-C exits keycodes(); } else { printf ("unknown command\r\n"); } }