# Key press in pop up window

**URL:** <https://forum.kirupa.com/t/key-press-in-pop-up-window/91110>\
**Category:** Uncategorized\
**Created:** [August 17, 2003, 3:58pm UTC](https://forum.kirupa.com/t/key-press-in-pop-up-window/91110 "2003-08-17T15:58:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![imported\_swift7777](https://avatars.discourse-cdn.com/v4/letter/i/b19c9b/32.png) [@imported\_swift7777](https://forum.kirupa.com/u/imported_swift7777)\
**Post date:** [August 17, 2003, 3:58pm UTC](https://forum.kirupa.com/t/key-press-in-pop-up-window/91110/1 "2003-08-17T15:58:28Z")

</div>

I’m in the process of building a hangman type game, which uses the keyboard as the source for input.

The game is launched in a centered pop-up window, but when you try to use the keyboard the key presses dont respond.

Here is the code:

initGame();  
stop();

function initGame() {  
// get phrase  
phrase = “Lucky Guess”;

```
// build display
display = "";
for(i=0;i&lt;phrase.length;i++) {
	// place spaces in the right spots
	if (phrase.charAt(i) == " ") {
		display = display + " ";

	} else {
		// place underscores in place of letters
		display = display + "_";
	}
}

```

}

function makeGuess(code) {  
// get the character that corresponds to the key pressed  
letter = String.fromCharCode(code);

```
// check to see if it is a letter
if (isAlpha(letter)) {

	// assume that the letter will not be found
	gotOne = false;

	// start building new display
	newDisplay = "";
	for(i=0;i&lt;phrase.length;i++) {

		// see if letters match
		if (phrase.charAt(i).toUpperCase() == letter.toUpperCase()) {

			// place letter in display text
			newDisplay = newDisplay + letter.toUpperCase();

			// note that at least one match has been found
			gotOne = true;

		} else {

			// not found, so display same character
			newDisplay = newDisplay + display.charAt(i) ;
		}
	}

	// show new display
	display = newDisplay;

	// if no match found, then add more to monster
	if (!gotOne) {
		monster.nextFrame();

		// see if the monster is done
		if (hangman._currentFrame == 7) {
			gotoAndPlay("lose");
		}

	} else if (display == phrase.toUpperCase()) {
		// the display matches the original, game over
		gotoAndPlay("win");
	}
}

```

}

// utility to test whether a character is in A-Z  
function isAlpha(letter) {  
// get character code  
n = letter.charCodeAt(0);

```
// convert low case to upper case
if (n &gt; 90) n -= 32;

// see if it is in A-Z
return ((n &gt;= 65) and (n &lt;= 90));

```

}

Also there is a root call:

onClipEvent (keyDown) {  
\_root.makeGuess(Key.getAscii());  
}

Which gives the keypress info to the makeGuess function,  
is the root of a pop-up the origonal window, or the pop-up window?

thanx in advance 4 any help.:rd:
