Author Topic: Getting text input from the keyboard - couple little snags  (Read 3696 times)

Bulbaboy

  • Regular
  • **
  • Posts: 36
    • View Profile
Hi again, been a while.  I need to get text input from the keyboard (or, better yet, from speech-to-text, but that's besides the point) for the project I'm currently working on, and I've got a few problems.

First off, I'd appreciate if someone could tell me how to implement backspace functionality - for those who know Perl, I believe it would be the equivalent of the "chop" function there.  You know, just something to cut off the last character in a string.  I suppose I might be able to figure this out myself, but it'd be nice to know how it's most easily done (and not have to deal with the MSDN docs as much).

Second, I notice that when I press Q, GameDev quits, just as if I had pressed escape.  Is there any way to turn this off without editing GameDev's source code, or am I screwed (in this case) unless I either learn enough to modify GameDev and/or switch to another program?  Assuming, of course, that I'll actually wind up wanting to use that letter.

Third, a more minor thing.  I'm currently using Variable = Variable & Chr(KeyCode), assuming that KeyCode is between 32 and 126 inclusive, but I notice that only works correctly for letters, numbers and the spacebar (and the letters are all uppercase).  Any easy way to make it print whatever key I press, or should I just change it so that it has to be space, a letter or a number for Chr(KeyCode) to go off?

And, last, but certainly not least, if someone's already got a sample script ready for just this kind of thing, could you guys tell me so I don't go reinventing the wheel, please ;)?

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Getting text input from the keyboard - couple little snags
« Reply #1 on: 2006-07-13, 05:44:00 AM »
Wheel: already invented

Code: here -  http://sourceforge.net/docman/display_doc.php?docid=26344&group_id=9970

Fix for "Q" key: Add this to the Select Case statement in the ProcessKeyDown function:
Code: [Select]
Case 81
  ProjectObj.GamePlayer.bQuit = False

I gotta admit that last one had me scared.  I thought there was no way to stop GameDev from quitting when you pressed Q and I was thinking "oh no, do I have to release a 1.4.7 for such a stupid mistake!?" but then I was relieved in looking at the source code to find this small hole through which I could control the quitting behavior.

Bulbaboy

  • Regular
  • **
  • Posts: 36
    • View Profile
Re: Getting text input from the keyboard - couple little snags
« Reply #2 on: 2006-07-14, 03:24:53 PM »
Cools, thanks, glad someone did it already.

And btw, that Q fix is to be inserted in the script file, right?  If so, it makes me very happy - sure, it takes a little extra effort, but not nearly as much as having to figure out how to recompile GameDev.  Now to just figure out if I need to use Q ;)...  Still prevents trouble if someone accidentally types Q instead of an A or W, though.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Getting text input from the keyboard - couple little snags
« Reply #3 on: 2006-07-14, 04:57:18 PM »
Yes, it goes in the script, not the GameDev code.

Bulbaboy

  • Regular
  • **
  • Posts: 36
    • View Profile
Re: Getting text input from the keyboard - couple little snags
« Reply #4 on: 2006-07-14, 08:50:16 PM »
It seems odd that it would work that way, but it's cool none-the-less.

bluemonkmn

  • SGDK Author
  • Administrator
  • Fanatic
  • *****
  • Posts: 2761
    • ICQ Messenger - 2678251
    • MSN Messenger - BlueMonkMN@gmail.com
    • View Profile
    • http://sgdk2.sf.net/
    • Email
Re: Getting text input from the keyboard - couple little snags
« Reply #5 on: 2006-07-15, 06:57:07 AM »
If it helps you understand why that works, here's what happens:
  • Every time a key is pressed, an event is raised from the Display object
  • GameDev receives the event from the display object and sees that it's a "Q" and it set's the player objects "bQuit" property to true to that next time it finishes drawing it will know that the player requested to quit and it will exit the main game loop
  • Next, the script receives the key event from the display (thank goodness it receives it afterwards).  It sees that it is a "Q" and realizes "Uh oh, that Q was going to make GameDev quit.  I better tell GameDev not to quit," so it does this by setting the bQuit property on the player object back to false (the script and GameDev engine share many of the same objects; that's what makes VB scripting with a VB 6 application so powerful and cool).
  • GameDev gets to the end of the game loop and checks bQuit on the player object to see if it was time to quit, and it's false so it doesn't quit and proceeds to play the game as if the player never requested to quit.