+ if (keycode < 0) /* want name for menu key? */
+ keycode = DRV(in_devices[dev_id].drv_id).menu_translate(keycode);
+
+ name = DRV(in_devices[dev_id].drv_id).get_key_name(keycode);
+ if (name != NULL)
+ return name;
+
+ /* assume scancode */
+ if ((keycode >= '0' && keycode <= '9') || (keycode >= 'a' && keycode <= 'z')
+ || (keycode >= 'A' && keycode <= 'Z'))
+ sprintf(xname, "%c", keycode);
+ else
+ sprintf(xname, "\\x%02X", keycode);
+ return xname;
+}
+
+int in_bind_key(int dev_id, int keycode, int mask, int bind_type, int force_unbind)
+{
+ int ret, count;
+ in_dev_t *dev;
+
+ if (dev_id < 0 || dev_id >= IN_MAX_DEVS || bind_type >= IN_BINDTYPE_COUNT)
+ return -1;
+
+ dev = &in_devices[dev_id];
+ count = dev->key_count;
+
+ if (dev->binds == NULL) {
+ if (force_unbind)
+ return 0;
+ dev->binds = in_alloc_binds(dev->drv_id, count);
+ if (dev->binds == NULL)
+ return -1;
+ }
+
+ if (keycode < 0 || keycode >= count)
+ return -1;
+
+ if (force_unbind)
+ dev->binds[IN_BIND_OFFS(keycode, bind_type)] &= ~mask;
+ else
+ dev->binds[IN_BIND_OFFS(keycode, bind_type)] ^= mask;
+
+ ret = DRV(dev->drv_id).clean_binds(dev->drv_data, dev->binds,
+ dev->binds + count * IN_BINDTYPE_COUNT);
+ if (ret == 0) {
+ free(dev->binds);
+ dev->binds = NULL;
+ }
+
+ return 0;
+}
+
+void in_unbind_all(int dev_id, int act_mask, int bind_type)
+{
+ int i, count;
+ in_dev_t *dev;
+
+ if (dev_id < 0 || dev_id >= IN_MAX_DEVS || bind_type >= IN_BINDTYPE_COUNT)
+ return;
+
+ dev = &in_devices[dev_id];
+ count = dev->key_count;
+
+ if (dev->binds == NULL)
+ return;
+
+ for (i = 0; i < count; i++)
+ dev->binds[IN_BIND_OFFS(i, bind_type)] &= ~act_mask;