Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

keypress?

Status
Not open for further replies.

martinb7

Programmer
Jan 5, 2003
235
GB
Hi, I have a dynamic textbox (variable = health), and I would like to know how to increase it to 999 or just increase it (e.g +2) when the SHIFT key and a letter like H is pressed

(SHIFT+H makes health = 999)

Any ideas??

Thanx

Martin

affiliates.gif
 
Stick this on the main timeline:

Code:
keyListener = {};
keyListener.onKeyDown = function() {
	if (key.isDown(Key.SHIFT) && Key.isDown(72)) {
		health += 2;
		trace('health='+health);
	}
};
Key.addListener(keyListener);
 
yes i have done that and it works - thanx ;). Now how would i add more keypresses like SHIFT + G into the code?

Thanx

Martin
 
The other key is controlled by the 'Key.isDown(72)' part, to add another key just replicate the 'if' statement code and change the number for the key code of the key you need to trap (G is 71).

If you're looking to catch a lot of keys then I'd have the 'SHIFT' condition separate from the rest and use a switch statement to work out what other key is being pressed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top