2 * Copyright (c) 1994 Joerg Wunsch
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Joerg Wunsch
17 * 4. The name authors may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * @(#)mcon.c, 3.20, Last Edit-Date: [Tue Dec 20 14:53:15 1994]
35 /*---------------------------------------------------------------------------*
39 * -jw initial version; includes a basic mapping between PeeCee
40 * scan codes and key names
41 * -hm changed sys/pcvt_ioctl.h -> machine/pcvt_ioctl.h
43 *---------------------------------------------------------------------------*/
46 * Utility program to wire the mouse emulator control ioctl to the
47 * user level. Allows setting of any configurable parameter, or
48 * display the current configuration.
51 #include <machine/pcvt_ioctl.h>
56 #include <sys/fcntl.h>
58 static const char *keynames[] = {
59 "", "esc", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0",
60 "-", "+", "bksp", "tab", "q", "w", "e", "r", "t", "y", "u",
61 "i", "o", "p", "[", "]", "enter", "ctrl", "a", "s", "d", "f",
62 "g", "h", "j", "k", "l", ";", "\"", "`", "lshift", "\\",
63 "z", "x", "c", "v", "b", "n", "m", ",", ".", "/", "rshift",
64 "prtscr", "alt", "space", "caps", "f1", "f2", "f3", "f4",
65 "f5", "f6", "f7", "f8", "f9", "f10", "numlock", "scrolllock",
66 "kp7", "kp8", "kp9", "kp-", "kp4", "kp5", "kp6", "kp+",
67 "kp1", "kp2", "kp3", "kp0", "kp."
71 const char *scantoname(int scan) {
72 if(scan >= sizeof keynames / sizeof(const char *))
75 return keynames[scan];
78 int nametoscan(const char *name) {
80 for(i = 0; i < sizeof keynames / sizeof(const char *); i++)
81 if(strcmp(keynames[i], name) == 0)
87 int main(int argc, char **argv) {
88 int c, errs = 0, fd, do_set = 0;
89 int left = 0, mid = 0, right = 0, accel = 0, sticky = -1;
90 struct mousedefs mdef;
92 while((c = getopt(argc, argv, "l:m:r:a:s:")) != -1)
95 left = nametoscan(optarg);
97 if(left == -1) goto keynameerr;
101 mid = nametoscan(optarg);
103 if(mid == -1) goto keynameerr;
107 right = nametoscan(optarg);
109 if(right == -1) goto keynameerr;
114 fprintf(stderr, "unknown key name: %s\n",
121 accel = 1000 * strtol(optarg, 0, 10);
126 if(strcmp(optarg, "0") == 0
127 || strcmp(optarg, "false") == 0
128 || strcmp(optarg, "no") == 0)
130 else if(strcmp(optarg, "1") == 0
131 || strcmp(optarg, "true") == 0
132 || strcmp(optarg, "yes") == 0)
135 fprintf(stderr, "invalid argument to -s: %s\n",
149 if(errs || argc != 1) {
150 fprintf(stderr, "usage: "
151 "mouse [-l key][-m key][-r key][-a acctime][-s 0|1] "
156 if((fd = open(argv[0], O_RDONLY)) < 0) {
157 perror("open(mousedev)");
160 if(ioctl(fd, KBDMOUSEGET, &mdef) < 0) {
161 perror("ioctl(KBDMOUSEGET)");
166 printf("Current mouse emulator definitions:\n"
168 "middle button: %s\n"
170 "acceleration limit: %d msec\n"
171 "sticky buttons: %s\n",
172 scantoname(mdef.leftbutton),
173 scantoname(mdef.middlebutton),
174 scantoname(mdef.rightbutton),
175 mdef.acceltime / 1000,
176 mdef.stickybuttons? "yes": "no");
180 if(left) mdef.leftbutton = left & 0x7f;
181 if(mid) mdef.middlebutton = mid & 0x7f;
182 if(right) mdef.rightbutton = right & 0x7f;
184 if(accel) mdef.acceltime = accel;
185 if(sticky != -1) mdef.stickybuttons = sticky;
187 if(ioctl(fd, KBDMOUSESET, &mdef) < 0) {
188 perror("ioctl(KBDMOUSESET)");