Page 1 of 1

how to detect a keypress of the ~ (or `) key in gui code?

Posted: Sun Sep 08, 2013 3:20 am
by Komag
So I'm experimenting with John's Quick Action Bar code a bit, and I want to have opening the console (by hitting the tilde ~ also known as the backtick ` key) be another control that toggles the quick bar on and off (so when I type stuff in the console it will stop triggering actions on the quickbar due to the hot keys!)

Anyway, I can't seem to figure out how to address the ~ key. When I just hit it, NOTHING types into the code window. If I test with some regular letter like q, that works for the test. If I hold Shift to get a ~ (instead of a `) then it will at least type into the window, but it doesn't work when testing the code, no results, not even if I hold Shift during the test. It's like the ` key doesn't exist!

In my grimrock.cfg I have the console on and see that the key is called 192, but that didn't work either (neither in quotes nor out of quotes).

Am I doing something wrong? Or is this just impossible? :?:

Re: how to detect a keypress of the ~ (or `) key in gui code

Posted: Mon Sep 09, 2013 8:56 am
by petri
You could try copy-pasting ~ from external text editor to dungeon editor. It's also likely that the gui system does not support "raw keys" like this. If that is the case then it's probably impossible to get this working...

Re: how to detect a keypress of the ~ (or `) key in gui code

Posted: Mon Sep 09, 2013 1:02 pm
by Komag
I can type a ~ but not a `, even copy paste just pastes nothing, very weird! I guess it's impossible :shock:

Re: how to detect a keypress of the ~ (or `) key in gui code

Posted: Mon Sep 09, 2013 1:49 pm
by JohnWordsworth
You might be able to do...

local c = string.char(65);

But replace 65 with the ASCII code for the key you want. And then use that value in the g.isKeyDown() method. (Typed on my mobile, so function names might be wrong, but the idea is that the GUI context might recognise all ASCII characters from the keyboard, even non-printable ones).

Re: how to detect a keypress of the ~ (or `) key in gui code

Posted: Mon Sep 09, 2013 3:01 pm
by Komag
Interesting, worth a shot