Added REL_#, ABS_#, KEY_# syntax

This commit is contained in:
Ingo Ruhnke 2010-05-31 01:56:57 +02:00
parent 35bc301140
commit bfc8e79527
6 changed files with 32 additions and 24 deletions

2
NEWS
View file

@ -5,6 +5,8 @@ xboxdrv 0.6.0 - (??/Jun/2010)
regular PC joysticks with xboxdrv, useful if you need
configurability or joy2key-like functionality, but don't have a
Xbox360 gamepad
* added KEY_#num, ABS_#num and REL_#num to allow refering to events by
number instead of name
xboxdrv 0.5.0 - (26/May/2010)

6
TODO
View file

@ -15,10 +15,6 @@ git push --tags
Stuff to do before 0.6.0 release:
=================================
* need support for numbers, not just names in evdev_helper, need special syntax to get the type:
KEY_1 is not unique, maybe: KEYNUM_1, ABSNUM_1, ...
* axis-min/max range must be transmitted to AxisEvent (maybe normalize to float)
* match by protocol not, just vendor/product, from xpad.c:
@ -43,8 +39,6 @@ Docu
* docu on how to write a wrapper script needs to be moved to xboxdrv manpage
* add a some general info to how xboxdrv works
Packaging
=========

View file

@ -446,6 +446,10 @@ mapping, except that the right hand side is an event name from
use all \fBKEY_\fR or \fBBTN_\fR
codes for \*(T<\fB\-\-ui\-buttonmap\fR\*(T>.
Aside from the named keys, you can also give the input
code directly as number via the
syntax \fBKEY_#\fINUM\fB\fR.
Instead of the low level \fBKEY_\fR names,
which represent keycodes, you can also use the higher
level X11 keysyms \fBXK_\fR, the keysyms have

View file

@ -593,6 +593,11 @@ DEVICEID = NUMBER ;]]></programlisting>
use all <keysym>KEY_</keysym> or <keysym>BTN_</keysym>
codes for <option>--ui-buttonmap</option>.
</para>
<para>
Aside from the named keys, you can also give the input
code directly as number via the
syntax <keysym>KEY_#<replaceable>NUM</replaceable></keysym>.
</para>
<para>
Instead of the low level <keysym>KEY_</keysym> names,
which represent keycodes, you can also use the higher

View file

@ -257,6 +257,7 @@ void set_evdev_keymap(std::map<int, XboxButton>& keymap, const std::string& str)
std::string lhs, rhs;
split_string_at(str, '=', &lhs, &rhs);
keymap[str2key(lhs)] = string2btn(rhs);
std::cout << "KEY: " << str2key(lhs) << std::endl;
}
void

View file

@ -675,21 +675,16 @@ int get_event_type(const std::string& name)
}
}
bool is_number_(const std::string& name)
{
for(std::string::const_iterator i = name.begin(); i != name.end(); ++i)
{
if (!isdigit(*i))
{
return false;
}
}
return true;
}
int str2abs(const std::string& name)
{
return evdev_abs_names[name];
if (name.compare(0, 5, "ABS_#") == 0)
{
return boost::lexical_cast<int>(name.substr(5));
}
else
{
return evdev_abs_names[name];
}
}
int str2key(const std::string& name)
@ -702,15 +697,15 @@ int str2key(const std::string& name)
{
return BTN_JOYSTICK + boost::lexical_cast<int>(name.substr(3));
}
else if (name.compare(0, 5, "KEY_#") == 0)
{
return boost::lexical_cast<int>(name.substr(5));
}
else if (name.compare(0, 3, "KEY") == 0 ||
name.compare(0, 3, "BTN") == 0)
{
return evdev_key_names[name];
}
else if (is_number_(name))
{
return boost::lexical_cast<int>(name);
}
else
{
throw std::runtime_error("str2key: couldn't convert string: '" + name + "'");
@ -719,7 +714,14 @@ int str2key(const std::string& name)
int str2rel(const std::string& name)
{
return evdev_rel_names[name];
if (name.compare(0, 5, "REL_#") == 0)
{
return boost::lexical_cast<int>(name.substr(5));
}
else
{
return evdev_rel_names[name];
}
}
UIEvent str2key_event(const std::string& str)