Author Topic: MODULE: ASCII keycodes  (Read 4267 times)

Akumayo

  • Is Watching You
    • I can help with AGS tutoring
    • I can help with play testing
    • I can help with scripting
    • I can help with story design
    • I can help with voice acting
    • Akumayo worked on one or more games that won an AGS Award!
    •  
    • Akumayo worked on one or more games that was nominated for an AGS Award!
MODULE: ASCII keycodes
« on: 01 Jan 2006, 19:29 »
'llo Again!  This module converts key text into ASCII code, so you don't have to remember all of it!

Example:
Code: [Select]
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
« Last Edit: 26 Apr 2006, 23:22 by strazer »
"Power is not a means - it is an end."

Re: MODULE: ASCII Text to Int converter
« Reply #1 on: 01 Jan 2006, 19:36 »
IMO it would be better to just define an enum like this:

Code: [Select]
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: [Select]
if (IsKeyPressed(eKeycode_ArrowRight) == 1) {

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

Akumayo

  • Is Watching You
    • I can help with AGS tutoring
    • I can help with play testing
    • I can help with scripting
    • I can help with story design
    • I can help with voice acting
    • Akumayo worked on one or more games that won an AGS Award!
    •  
    • Akumayo worked on one or more games that was nominated for an AGS Award!
Re: MODULE: ASCII Text to Int converter
« Reply #2 on: 01 Jan 2006, 19:38 »
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

  • Creator of AGS
  • Administrator
  • Mittens King
  • I sense danger.
    • Lifetime Achievement Award Winner
    • Pumaman worked on one or more games that won an AGS Award!
    •  
    • Pumaman worked on one or more games that was nominated for an AGS Award!
Re: MODULE: ASCII Text to Int converter
« Reply #3 on: 04 Jan 2006, 13:58 »
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
« Last Edit: 20 Apr 2006, 02:27 by strazer »

Re: MODULE: ASCII Text to Int converter
« Reply #4 on: 07 Jan 2006, 16:21 »
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
« Last Edit: 20 Apr 2006, 02:26 by strazer »