Adventure Game Studio | Forums

AGS Support => Modules, Plugins & Tools => Topic started by: Akumayo on Sun 01/01/2006 19:29:55

Title: MODULE: ASCII keycodes
Post by: Akumayo on Sun 01/01/2006 19:29:55
'llo Again!  This module converts key text into ASCII code, so you don't have to remember all of it!

Example:

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 (http://www.2dadventure.com/ags/akumayosasciiquickconverter.zip) (Thanks Neole!)

-Regards, Akumayo
Title: Re: MODULE: ASCII Text to Int converter
Post by: strazer on Sun 01/01/2006 19:36:36
IMO it would be better to just define an enum like this:


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


if (IsKeyPressed(eKeycode_ArrowRight) == 1) {


Here is my module: http://www.strazer.net/ags/Keycodes.zip
Title: Re: MODULE: ASCII Text to Int converter
Post by: Akumayo on Sun 01/01/2006 19:38:40
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...
Title: Re: MODULE: ASCII Text to Int converter
Post by: Pumaman on Wed 04/01/2006 13:58:49
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
Title: Re: MODULE: ASCII Text to Int converter
Post by: strazer on Sat 07/01/2006 16:21:36
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