Waiting for a Specific Keystroke

My game is going to have a few text walls in it, and I’d hate for someone to accidentally skip a crucial part of the dialog. If there was a way to wait for a specific key to be pressed instead of ‘any key’, I’d be very happy. Accidentally skipping a bit of dialog or exposition in a game that is clearing the screen may be the bane of my existence, so I’d like to go to extremes to avoid that.

I suspect this is an I6 sort of thing, so I’ve come to the forum for help. If there is a simple way to do this with Inform7 code, I’m not aware of it.

Thanks in advance to the old code knight that fixes my issue.

You can “wait for SPACE key”, i believe.

Yep, you can use that, but will have to provide your own prompt as it doesn’t print one automatically.

say "Press space to continue.";
wait for SPACE key.

You’re absolutely right, and I forgot to do that in my introcomp entry! :blush:

I’ll probably go with that for now, but if there were some way to use a different key, that would be ideal. The space key tends to be a little clunky.

Seems like there should be a way to check for other keys with the Basic Screen Effects extension. While looking in its code I see the following lines:

To decide what number is the chosen letter:
	(- GetKey() -)

But I can’t for the life of me figure how to use this…not much time to play with it at the moment though.

I definitely think you’re onto something. I’ll dig around and try to find the rest of that functionality.

Another odd thing I noticed as I was using the space key method, is that whenever I do press space to continue, I hear a sound play as if I pressed an invalid key.

Any ideas?


After searching around, I found this thread.
It seems that there is some way to do what I want using this hidden feature, but I’m not sure how.
The last reply on the thread is right on the money, but I’m not sure how to convert that to something that will wait until that key is pressed.

I’m going to mess around with it and see if I can come up with something.

Here’s what I’ve got, using most of Erik’s code from the other thread. It does exactly what I want, mostly.

Keychar is a number variable. [setting up the parser to identify specific key presses during transitions]
Keypress is an indexed text variable.
To get char input:
now keychar is the chosen letter;
now keypress is keychar resolved to an indexed text.

To decide which indexed text is (N - a number) resolved to an/-- indexed text:
if (N > 31 and N < 127) or (N > 160 and N < 384):[i.e., we have received printable input]
decide on “[char-code (N)]”;
decide on “”.

To say char-code (N - a number):
(- print (char) {N}; -)[/code]
Then, put this bit wherever you want the wait to occur:

while keypress is not "c": get char input;

I’ll still need to figure out how to clear the parser between each press though.

What do you mean by “clear the parser”?

EDIT-ADD: Oh, I bet you want this:

	say "Prompt: ";
	now keypress is "";
	while keypress is not "c":
		get char input.

Not quite. As you’re typing letters other than ‘c’, the parser is filling up with characters. It looks quite sloppy.

By parser, I’m referring to the text box where you type in commands.

For example, if it’s waiting for someone to press ‘z’ and they press some other keys first, the parser will look like this:

It shouldn’t. Nothing in that code sample prints the character being input. What interpreter are you using?

It’s not being printed. I’m talking about the input box where the player types. Since no part of this command involves the enter key, that box is not being cleared.

Why don’t you just use the SPACE key? Sounds like it would be simpler and let you get back to the story itself. :question:

The input widget is interpreter-specific, but it should not display characters during keystroke input. What interpreter are you using?

I don’t like waiting for specific keys, unless it’s Space. I think you should wait for any key other than navigation keys such as Up/Down and PageUp/Down. This is some code I’m working on now:

[ Wait for a safe non navigating key. The user might press Down/PgDn or use the mouse scroll wheel when reading a menu page, so we will stop those key codes from returning to the menu. ] To wait for any non navigating key: while 1 is 1: let key be the chosen letter; [ Exclude Up/Down/PgUp/PgDn and ? which Gargoyle+Bocfel returns for unknown keys such as PgDn/Mouse scroll. Both Z-Machine and Glulx key codes are handled ] if key is 63 or key is 129 or key is 130: next; if key < 0: if key is -8 or key is -6: stop; next; stop;

If you use the numbers it will be faster than converting to text with indexed text.

(It’s not perfect - other interpreters return strange keycodes for PgUp/Dn and mouse scrolling which I need to add.)

I’m using the Glulxe interpreter. If I have to, I’ll just allow the junk keys. I really don’t want to let space advance the text, since in my experience the key you’re most likely to press by accident is the space bar.

I understand your concern, but I think most IFers are more competent at their keyboards than that. Just saying, it’s never happened to me when I play. I could be in the minority, I guess. Best of luck with the game! :slight_smile:

Only time I ever have problems with the space bar is when I’m playing on my phone or tablet. But never a big concern for me regardless.

Damn, you’re right, I didn’t think about people playing on devices. (Cuz I don’t have one of those devices, lol)

I only play on one when I’m away from home and bored. No real serious play though.