1 /* 2 * modifiers - asserts (un)pressed modifier keys 3 * (c) 2002, Francois Revol, revol@free.fr 4 * for OpenBeOS 5 * compile with: 6 * LDFLAGS=-lbe make modifiers 7 */ 8 9 #include <OS.h> 10 #include <stdio.h> 11 #include <strings.h> 12 #include <InterfaceDefs.h> 13 14 15 int32 modifier_bits[] = { 16 B_SHIFT_KEY, 17 B_COMMAND_KEY, 18 B_CONTROL_KEY, 19 B_CAPS_LOCK, 20 B_SCROLL_LOCK, 21 B_NUM_LOCK, 22 B_OPTION_KEY, 23 B_MENU_KEY, 24 B_LEFT_SHIFT_KEY, 25 B_RIGHT_SHIFT_KEY, 26 B_LEFT_COMMAND_KEY, 27 B_RIGHT_COMMAND_KEY, 28 B_LEFT_CONTROL_KEY, 29 B_RIGHT_CONTROL_KEY, 30 B_LEFT_OPTION_KEY, 31 B_RIGHT_OPTION_KEY, 32 0 33 }; 34 35 36 const char *modifier_names[] = { "shift", "command", "control", "capslock", "scrolllock", "numlock", "option", "menu", "lshift", "rshift", "lcommand", "rcommand", "lcontrol", "rcontrol", "loption", "roption", NULL }; 37 38 39 int 40 usage(char *progname, int error) 41 { 42 FILE *outstr; 43 outstr = error?stderr:stdout; 44 fprintf(outstr, "Usage: %s [-help] [-list] [-/+][[|l|r][shift|control|command|option]|capslock|scrolllock|numlock|menu]\n", progname); 45 fprintf(outstr, "\t- asserts unpressed modifier,\n"); 46 fprintf(outstr, "\t+ asserts pressed modifier,\n"); 47 return error; 48 } 49 50 51 int 52 list_modifiers(int mods) 53 { 54 int i; 55 int gotone = 0; 56 for (i=0; modifier_names[i]; i++) { 57 if (mods & modifier_bits[i]) { 58 if (gotone) 59 printf(","); 60 gotone = 0; 61 printf("%s", modifier_names[i]); 62 gotone = 1; 63 } 64 if (modifier_names[i+1] == NULL) 65 printf("\n"); 66 } 67 return 0; 68 } 69 70 71 int 72 main(int argc, char **argv) 73 { 74 int32 mods; 75 int32 mask_xor = 0x0; 76 int32 mask_and = 0x0; 77 int i, j; 78 79 mods = modifiers(); 80 if (argc == 1) 81 return usage(argv[0], 1); 82 for (i=1; i<argc; i++) { 83 if (!strncmp(argv[i], "-h", 2)) 84 return usage(argv[0], 0); 85 else if (!strcmp(argv[i], "-list")) 86 return list_modifiers(mods); 87 else if (strlen(argv[i]) > 1 && (*argv[i] == '-' || *argv[i] == '+')) { 88 for (j=0; modifier_names[j]; j++) { 89 if (!strcmp(argv[i]+1, modifier_names[j])) { 90 if (*argv[i] == '-') 91 mask_and |= modifier_bits[j]; 92 else 93 mask_xor |= modifier_bits[j]; 94 break; 95 } 96 } 97 if (modifier_names[j] == NULL) 98 return usage(argv[0], 1); 99 } else 100 return usage(argv[0], 1); 101 } 102 mask_and |= mask_xor; 103 return (((mods & mask_and) ^ mask_xor) != 0); 104 } 105 106