MODULE: ASCII keycodes

Started by Akumayo, Sun 01/01/2006 19:29:55

Previous topic - Next topic

Akumayo

'llo Again!  This module converts key text into ASCII code, so you don't have to remember all of it!

Example:
Code: ags

repeatedly_execute () {
  if (IsKeyPressed(GetASCIINumber(RightArrowKey)) == 1) {
    //Execute code if the player pressed the right arrow key
  }
}


See?  Now you don't have to memorize ASCII or go back and look at it all the time!  This module supports EVERY ASCII code that AGS does.

Download here (Thanks Neole!)

-Regards, Akumayo
"Power is not a means - it is an end."

strazer

IMO it would be better to just define an enum like this:

Code: ags

enum Keycodes {
	eKeycode_Backspace = 8, 
	eKeycode_Enter = 13, 
	eKeycode_Esc = 27, 
	eKeycode_Space = 32, 
	eKeycode_Tab = 9, 

	eKeycode_ArrowDown = 380, 
	eKeycode_ArrowLeft = 375, 
	eKeycode_ArrowRight = 377, 
	eKeycode_ArrowUp = 372, 

	eKeycode_Num5 = 376, 
	eKeycode_NumEnd = 379, 
	eKeycode_NumHome = 371, 
	eKeycode_NumPgDn = 381, 
	eKeycode_NumPgUp = 373, 

	eKeycode_F1 = 359, 

...and so on.

So in your example it would be

Code: ags

if (IsKeyPressed(eKeycode_ArrowRight) == 1) {


Here is my module: http://www.strazer.net/ags/Keycodes.zip

Akumayo

Meh... someone always beats me to it.... anyway, I just threw the module together because it's useful in RPG's when you have key based interface...  Either module would work for the same purpose I suppose...
"Power is not a means - it is an end."

Pumaman

#3
Good idea ... AGS itself should really provide constants for the keypresses, but this is a good way of doing it in the meantime.

Edit by strazer:

Tracker'd: http://www.adventuregamestudio.co.uk/tracker.php?action=detail&id=553

strazer

#4
I think my way is more simple and elegant, but yeah, both will do the job just fine.

Btw, when you import my module and change your on_key_press function from
  function on_key_press(int keycode) {
to
  function on_key_press(Keycodes keycode) {
the list of available keys pops up once you type
  if (keycode ==

But of course even without these modules, for normal keys you can simply do
  if (keycode == 'A') { // if key A or a pressed

SMF spam blocked by CleanTalk