From 24fd7f4b45d2083fd9e22d4bc232e03cbe7e7ba8 Mon Sep 17 00:00:00 2001 From: Bukz Date: Wed, 6 Feb 2013 04:18:56 +0000 Subject: [PATCH] new commands findkey & findkeycode git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@7154 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- config/docs.cfg | 14 ++++++++++++++ source/src/console.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/config/docs.cfg b/config/docs.cfg index bfd225d7..e7e4834b 100644 --- a/config/docs.cfg +++ b/config/docs.cfg @@ -183,6 +183,18 @@ docargument [S] [the string to execute] [] [0]; docexample [execute (concat echo (addpunct fov 3))] [Example output: 90.0]; docident [findcn] [find client number (cn)]; docargument [N] [NAME] [] [0]; +docident [findkey] [Returns the name of a key via a specified code.]; +docargument [I] [integer] [] [0]; +docremark [Returns -255 if the key does not exist.]; +docremark [See /config/keymap.cfg for a full list of valid key codes.]; +docexample [echo (findkey 8)] [Output: BACKSPACE]; +docexample [echo (findkey 280)] [Output: PAGEUP]; +docident [findkeycode] [Returns the integer code of a key.]; +docargument [K] [the name of the key] [] [0]; +docremark [Returns -255 if the key does not exist.]; +docremark [See /config/keymap.cfg for a full list of valid key names.]; +docexample [echo (findkeycode BACKSPACE)] [Output: 8]; +docexample [echo (findkeycode PAGEUP)] [Output: 280]; docident [findlist] [Searches a list for a specified value.]; docargument [L] [the list] [] [0]; docargument [I] [the item to find] [] [0]; @@ -208,6 +220,8 @@ docexample [const hello ""; echo (isconst hello)] [Output: 1]; docexample [hello = value; echo (isconst hello)] [Output: 0]; docident [isIdent] [returns whether or not there is an identifier by that name]; docargument [N] [identifier name] [] [0]; +docident [keybind] [Returns the contents of a keybind.]; +docargument [K] [name of key] [] [0]; docident [l0] [leading zeros for the number V to make it W chars wide. It may look like 10 - which might be considered a mnemonic - but it's lowercase-L and 0!]; docargument [W] [WIDTH] [] [0]; docargument [V] [VALUE] [] [0]; diff --git a/source/src/console.cpp b/source/src/console.cpp index 239e1036..5c63d836 100644 --- a/source/src/console.cpp +++ b/source/src/console.cpp @@ -206,6 +206,39 @@ keym *findbindc(int code) return NULL; } +void findkey(int *code) +{ + for (int i = 0; i < keyms.length(); i++) + { + if(keyms[i].code==*code) + { + defformatstring(out)("%s", keyms[i].name); + result(out); + return; + } + } + result("-255"); + return; +} + +void findkeycode(const char* s) +{ + for (int i = 0; i < keyms.length(); i++) + { + if(strcmp(s, keyms[i].name) == 0) + { + defformatstring(out)("%i", keyms[i].code); + result(out); + return; + } + } + result("-255"); + return; +} + +COMMAND(findkey, "i"); +COMMAND(findkeycode, "s"); + keym *keypressed = NULL; char *keyaction = NULL;