2 * modifiers - asserts (un)pressed modifier keys
3 * (c) 2002, Francois Revol, revol@free.fr
6 * LDFLAGS=-lbe make modifiers
13 #include <InterfaceDefs.h>
16 int32 modifier_bits
[] = {
37 const char *modifier_names
[] = { "shift", "command", "control", "capslock", "scrolllock", "numlock", "option", "menu", "lshift", "rshift", "lcommand", "rcommand", "lcontrol", "rcontrol", "loption", "roption", NULL
};
41 usage(char *progname
, int error
)
44 outstr
= error
?stderr
:stdout
;
45 fprintf(outstr
, "Usage: %s [-help] [-list] [-/+][[|l|r][shift|control|command|option]|capslock|scrolllock|numlock|menu]\n", progname
);
46 fprintf(outstr
, "\t- asserts unpressed modifier,\n");
47 fprintf(outstr
, "\t+ asserts pressed modifier,\n");
53 list_modifiers(int mods
)
57 for (i
=0; modifier_names
[i
]; i
++) {
58 if (mods
& modifier_bits
[i
]) {
62 printf("%s", modifier_names
[i
]);
65 if (modifier_names
[i
+1] == NULL
)
73 main(int argc
, char **argv
)
82 return usage(argv
[0], 1);
83 for (i
=1; i
<argc
; i
++) {
84 if (!strncmp(argv
[i
], "-h", 2))
85 return usage(argv
[0], 0);
86 else if (!strcmp(argv
[i
], "-list"))
87 return list_modifiers(mods
);
88 else if (strlen(argv
[i
]) > 1 && (*argv
[i
] == '-' || *argv
[i
] == '+')) {
89 for (j
=0; modifier_names
[j
]; j
++) {
90 if (!strcmp(argv
[i
]+1, modifier_names
[j
])) {
92 mask_and
|= modifier_bits
[j
];
94 mask_xor
|= modifier_bits
[j
];
98 if (modifier_names
[j
] == NULL
)
99 return usage(argv
[0], 1);
101 return usage(argv
[0], 1);
103 mask_and
|= mask_xor
;
104 return (((mods
& mask_and
) ^ mask_xor
) != 0);