Keyboard Assocation

I’m using Emily Short’s “Menus” and “Basic Screen Effects.” The player can navigate the menus by using keystrokes. For instance, pushing ENTER causes the selected item to activate, while pushing the UP arrow changes which item is selected. She’s already mapped several keys with functions:

78 move down rule
110 move down rule
80 move up rule
112 move up rule
81 quit rule
113 quit rule
13 select rule
32 select rule
130 move down rule
129 move up rule
27 quit rule

I’d like to add the ESC key to this list as a quit rule. I can’t figure out what number ESC is associated with, though. Does anyone know how to figure this out?

What I’ve found so far: these numbers are relayed through “Basic Screen Effects” to use the function “GetKey()”. I cannot find any other reference to “GetKey(),” though. Not in the documentation nor in the standard rules.

I would guess it to be 27 (using the ASCII table), but a quit-rule with 27 is already listed. That isn’t working?

(You almost certainly want to test this with a released version of your game, because the IDE might be capturing some keys.)

Just tried it on a released version, and still no luck. That’s strange, though. The other keys are matched up with the ASCII table, so why wouldn’t it recognize ESC? I’ve tried using my ESC key with other programs, it works fine with them. Maybe another extension is interfering? I’ll look into it.

You want -8 if you’re compiling to Glulx; for z-code use 27. To find the value of any key, you can do something like this:

[code]Include Basic Screen Effects by Emily Short.

When play begins:
say “Press a key.”;
let N be the chosen letter;
say “You pressed: [N].”[/code]

–Erik

-8 Does the trick! Thanks for the help.

On a similar note, I want to have a menu pop up every time the player presses ESC. Is there a way to do this in inform? Specifically, is there a way to recognize when the player pushes ESC?

It’s possible, but complicated. Basically, you’d need to reimplement the basic input model (type a string and then register it using the return key) using the single-keypress model (each key registers as it’s pressed). Jon Ingold’s Interactive Parsing does this. Currently it looks like the ESC registers as a space, but you ought to be able to change that. I’m not sure that it would be worth it if you didn’t want Interactive Parsing’s other features, though.

–Erik

Interactive Parsing looks promising. I’ve installed and fiddled with the code, but unfortunately, the relevant bits are written in Inform 6 and not Inform 7. Specifically:

                         [code]  ! escape key
				keycode_Escape:
					if (cursor_position > 0)
					{
						InsertCharacterAt(' ', a_buffer, cursor_position);
						!a_buffer->(WORDSIZE + type_position) = ' ';
						ResetRunningChecks();
						BlankSuggestion();
						cursor_position++;
					}[/code]

I tried following this with the following statement:

otherwise, carry out the summing main menu activity

Unfortunately, this gets an error. Is there an easy translation of this into Inform 6?

else CarryOutActivity((+ the summing main menu activity +));

I think you’ll probably have to do more than just fire the menu activation rules. You’ll also need to suspend or cancel the main game input, as well as restart it when you’re done with the menu. Depending on how the extension’s code is set up, this may be easy or it may be hard, and you may or may not have to write in I6 as well as I7.

–Erik

Thanks for the suggestion, Emacs, but for some reason it’s giving a buggy response. The main menu doesn’t come up, but instead I get some nonsense text about a door. My feeling is that it’s not worth the effort. The player can still type “Menu” or I can even insert a hyperlink to bring up the menu screen. There are definitely options. Thanks, anyway!