From 9eac4585b15b6741f129f93fd3f2c5dcb08b61a0 Mon Sep 17 00:00:00 2001 From: lethosor Date: Wed, 2 Sep 2015 15:56:53 -0400 Subject: [PATCH] keybinding: support 0-9, F10-F12 --- NEWS | 1 + Readme.rst | 4 ++-- library/Core.cpp | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 4e20592e2..be8be21cd 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,7 @@ DFHack Future Stopped DF window from receiving input when unfocused on OS X Fixed issues with keybindings involving Ctrl-A and Ctrl-Z, as well as Alt-E/U/N on OS X Multiple contexts can now be specified when adding keybindings + Keybindings can now use F10-F12 and 0-9 Plugin system is no longer restricted to plugins that exist on startup Lua Scripts can be enabled with the built-in enable/disable commands diff --git a/Readme.rst b/Readme.rst index d68755cb2..bb8e2bf7f 100644 --- a/Readme.rst +++ b/Readme.rst @@ -197,7 +197,7 @@ To set keybindings, use the built-in ``keybinding`` command. Like any other command it can be used at any time from the console, but it is also meaningful in the DFHack init file. -Currently it supports any combination of Ctrl/Alt/Shift with F1-F9, or A-Z. +Currently, any combinations of Ctrl/Alt/Shift with A-Z, 0-9, or F1-F12 are supported. Possible ways to call the command: @@ -214,7 +214,7 @@ The ** parameter above has the following *case-sensitive* syntax:: [Ctrl-][Alt-][Shift-]KEY[@context[|context...]] -where the *KEY* part can be F1-F9 or A-Z, and [] denote optional parts. +where the *KEY* part can be any recognized key and [] denote optional parts. When multiple commands are bound to the same key combination, DFHack selects the first applicable one. Later 'add' commands, and earlier entries within one diff --git a/library/Core.cpp b/library/Core.cpp index 3cb86896a..9f7709c3a 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -2157,9 +2157,15 @@ static bool parseKeySpec(std::string keyspec, int *psym, int *pmod, std::string if (keyspec.size() == 1 && keyspec[0] >= 'A' && keyspec[0] <= 'Z') { *psym = SDL::K_a + (keyspec[0]-'A'); return true; + } else if (keyspec.size() == 1 && keyspec[0] >= '0' && keyspec[0] <= '9') { + *psym = SDL::K_0 + (keyspec[0]-'0'); + return true; } else if (keyspec.size() == 2 && keyspec[0] == 'F' && keyspec[1] >= '1' && keyspec[1] <= '9') { *psym = SDL::K_F1 + (keyspec[1]-'1'); return true; + } else if (keyspec.size() == 3 && keyspec.substr(0, 2) == "F1" && keyspec[2] >= '0' && keyspec[2] <= '2') { + *psym = SDL::K_F10 + (keyspec[2]-'0'); + return true; } else if (keyspec == "Enter") { *psym = SDL::K_RETURN; return true;