Added "nul" binds.

This commit is contained in:
Themaister 2011-02-26 18:47:32 +01:00
parent f75c6df270
commit 13f8ec6f3b
2 changed files with 38 additions and 23 deletions

View File

@ -545,6 +545,7 @@ static const struct key_map sdlk_map[] = {
{ "f10", SDLK_F10 },
{ "f11", SDLK_F11 },
{ "f12", SDLK_F12 },
{ "nul", SDLK_UNKNOWN },
};
static struct snes_keybind *find_snes_bind(unsigned port, int id)
@ -578,6 +579,7 @@ static int find_sdlk_key(const char *str)
return find_sdlk_bind(str);
}
// Yes, this function needs a good refactor :)
static void read_keybinds(config_file_t *conf)
{
char *tmp_key = NULL;
@ -606,37 +608,48 @@ static void read_keybinds(config_file_t *conf)
if (bind_maps[j][i].btn && config_get_string(conf, bind_maps[j][i].btn, &tmp_btn))
{
const char *btn = tmp_btn;
if (*btn++ == 'h')
if (strcmp(tmp_btn, "nul") == 0)
{
if (isdigit(*btn))
{
char *dir = NULL;
int hat = strtol(btn, &dir, 0);
int hat_dir = 0;
if (dir)
{
if (strcasecmp(dir, "up") == 0)
hat_dir = HAT_UP_MASK;
else if (strcasecmp(dir, "down") == 0)
hat_dir = HAT_DOWN_MASK;
else if (strcasecmp(dir, "left") == 0)
hat_dir = HAT_LEFT_MASK;
else if (strcasecmp(dir, "right") == 0)
hat_dir = HAT_RIGHT_MASK;
if (hat_dir)
bind->joykey = HAT_MAP(hat, hat_dir);
}
}
bind->joykey = NO_BTN;
}
else
bind->joykey = strtol(tmp_btn, NULL, 0);
{
if (*btn++ == 'h')
{
if (isdigit(*btn))
{
char *dir = NULL;
int hat = strtol(btn, &dir, 0);
int hat_dir = 0;
if (dir)
{
if (strcasecmp(dir, "up") == 0)
hat_dir = HAT_UP_MASK;
else if (strcasecmp(dir, "down") == 0)
hat_dir = HAT_DOWN_MASK;
else if (strcasecmp(dir, "left") == 0)
hat_dir = HAT_LEFT_MASK;
else if (strcasecmp(dir, "right") == 0)
hat_dir = HAT_RIGHT_MASK;
if (hat_dir)
bind->joykey = HAT_MAP(hat, hat_dir);
}
}
}
else
bind->joykey = strtol(tmp_btn, NULL, 0);
}
free(tmp_btn);
}
if (bind_maps[j][i].axis && config_get_string(conf, bind_maps[j][i].axis, &tmp_axis))
{
if (strlen(tmp_axis) >= 2 && (*tmp_axis == '+' || *tmp_axis == '-'))
if (strcmp(tmp_axis, "nul") == 0)
{
bind->joyaxis = AXIS_NONE;
}
else if (strlen(tmp_axis) >= 2 && (*tmp_axis == '+' || *tmp_axis == '-'))
{
int axis = strtol(tmp_axis + 1, NULL, 0);
if (*tmp_axis == '+')

View File

@ -90,6 +90,8 @@
# input_axis_threshold = 0.5
# Keyboard input. Will recognize normal keypresses and special keys like "left", "right", and so on.
# Keyboard input, Joypad and Joyaxis will all obey the "nul" bind, which disables the bind completely,
# rather than relying on a default.
# input_player1_a = x
# input_player1_b = z
# input_player1_y = a