I am having a problem getting user input using allegro 5. I have seen all thecomments on this site concerning user input! All the comments seem to be somewhat over my head! I have just started using allegro 5. What I am concerned with isgetting user input from the keyboard such as a user's name. I would prefer thatit would be in ascii text using graphics mode. If someone could post a small portionof code in C language showing a switch statement I would be most grateful. If youwould like more info I would be glad to post it. Thanks to all that would like tohelp me with this problem.There was one post by AmnesiA that was posted on 9-27-2013 @ 9:58 AM that was veryhelpful but I never got anything it to work.

It's really not that hard. Hook an event queue up to the keyboard and listen for ALLEGRO_EVENT_KEY_CHAR events. Listen for ev.keyboard.unichar and ev.keyboard.keycode to determine what to do with the input.

Good morning Edgar: I plugged your code into my program and code:blocks generated a few errors.Some I have no idea what to do about! So, after 3 weeks dealing with this oneproblem, I have had enough! I am going to try to forget about it! Maybe laterI will try again. I appreciate your time but Allegro is too much of a problemfor me! I had to give up on Python for the exact same reason. Thanks for yourtime but it appears I can't master that keyboard! Have a great day my friend!

Good morning Edgar:I plugged your code into my program and code:blocks generated a few errors.Some I have no idea what to do about! So, after 3 weeks dealing with this oneproblem, I have had enough! I am going to try to forget about it! Maybe laterI will try again. I appreciate your time but Allegro is too much of a problemfor me! I had to give up on Python for the exact same reason. Thanks for yourtime but it appears I can't master that keyboard! Have a great day my friend!

Scooter,If you keep giving up you'll never learn anything. Failure is normal. You need to keep going. When you get an error, read what it says, usually they help you figure out what is wrong. Also, you need some basic C programming skills. Python is actually not that difficult to understand.

Don't just plug code into your program. You need to understand what it does. Copy Paste Coding is the Source of all EvilTM.

I appreciate your concern!I have accomplished many GREAT things in my lifetime.I consider what little programming I do to be a lot of FUN!If it ever becomes NOT FUN, then I consider it NOT WORTHWHILE!Not everyone can become an expert in programming!

We can help answer any questions you may have, but you need a good book on Programming in C. There are a lot of good websites out there too, such as http://cppreference.com (which has a good C reference as well). Once you're comfortable with C, you need to become comfortable with reading documentation for the libraries you're using, such as http://liballeg.org/a5docs/trunk/ .

Good afternoon Edgar: I may have left the wrong impression. I have been using the C language off andon for the last 25 to 30 years. I don't consider myself an expert but I do have manyprograms I have written. I started back in the day when Borland Turbo C was popular.I guess I just told my age. Nonetheless, I am somewhat familiar with Allegro 5. Ihave a Poker game I have written and a program displaying my favorite cars in a slideshow with music playing in the background. These programs all use the mouse tonavigate through the program. I would not consider either one professional, but theyboth work perfectly. My main problem is the keyboard. None of the programs I havefound are using the keyboard like I am trying to. I do not have a problem with usingthe arrow keys like many of the programs show. What I want to do is press a key andit show on the screen the key I pressed. This would be like a person's name whichwould be copied to a structure like an address book. None of the programs show howthis is done in Allegro 5. I guess my problem is the syntax in Allegro 5. At my agethis is something I do for fun and fun only. I have no intention of being a pro-fessional programmer. I appreciate your help but I wanted to let you know what mygoals were. Have a great day!

What you need to understand about Allegro 5 is that it uses events. Keyboard information comes in the form of events. There are ALLEGRO_EVENT_KEY_DOWN, ALLEGRO_EVENT_KEY_UP, and ALLEGRO_EVENT_KEY_CHAR events. When you need to know what key was pressed you use ALLEGRO_EVENT_KEY_DOWN, and when you need to know what character was typed, you use ALLEGRO_EVENT_KEY_CHAR.

You may not be aspiring to be a professional programmer, but at the same time, this is pretty simple stuff. I believe that if a person is going to do something, they should do it to the best of their ability or not at all. Giving up because something is hard is self destructive. You will start to believe that you can't do it, and if you believe you can't then you actually can't do it. It's a self fulfilling prophecy. However, if you believe you can, you can. Mind set is everything.

They use two functions to display the character. al_utf8_encode, and al_keycode_to_name. The first gives you the character's unicode code point, and the second gives you the name of the key that was pressed. Notice how al_utf8_encode takes ev.keyboard.unichar? And al_keycode_to_name takes ev.keyboard.keycode?

Had no luck with your code segment! Finally wrote what I needed in C, awayfrom Allegro. Entered my info, saved to disk and loaded into my Allegro program.A little extra work but worked out fine! That was my only hope! There is somethingabout that keyboard in Allegro that I can't understand. But I got the job doneand I am happy. Too many sleepless nights worrying about it! Thanks for your time.

Neil: Thanks for replying. I am going to try this again. I believe my problemis the unichar. How would it look to use ascii text. Using the unichar myprogram compiles fine, but when I sprintf the string in my buffer and usetextf to print buffer to screen, nothing shows on the screen. I really don'tknow where my problem is. I have tried different ways and they all compile withno warnings or errors, but I can't get a thing printed to the screen. That isthe reason I broke away from allegro and wrote it in straight C to get the jobdone. I then saved my info to disk, brought up allegro and imported my infoto my structure and then printed to the screen. Everything worked as I wanted.I believe I need to use straight ascii text and I would be fine. Any ideas onthat. Thanks for your time. This seems to be my main problem using allegro 5.I have no problem with the arrow keys or the mouse.

My function above uses unicode to support all sorts of text as I have had people play my game from all over the world and there needed to be support for international characters etc. It wasn't difficult to be honest.

The one problem I had when I first converted over to unichar or whatever in heck they are called (been a while). Was my main project files needed to be encoded as UTF-8 files.

If you look at the source I shared, it works (download and run my Deluxe Pacman 2 game, that is the code straight from that game for the high score input).

If you look at my code, you will see I use special Allegro functions which will assign unicode text to things like my highscore array.

As you can see, the "name" part of the struct where I store the text NEEDS to be an ALLEGRO_USTR in order to be able to store it properly.

It may seem like a bit of a pain now, but it really is worth it to understand how to handle unicode if you wish to make anything that can be used internationally. For my Deluxe Pacman games, I have had literally millions of downloads (free game), most from South America and other foreign nations, so the unicode support was a good thing to have. If your text is not appearing it could be due to not storing it properly or using the right functions to display it.

Go over your code a step at a time.

1) Am I using unicode storage? ALLEGRO_USTR2) am I copying text using unicode functions? al_ustr_assign()3) am I using unicode functions to display it?

etc... you can do this. I know, I was frustrated with this as well until one day when you get it right.

Feel free to needlessly complicate things by using an ALLEGRO_USTR if you want Neil. The lower byte of ev.keyboard.unichar IS ascii, due to the way it is encoded. And you have to check for the upper bound as well, not just the lower bound.

If you want to use pure ASCII, than ditch Unicode entirely and just do ASCII. It is absolutely pointless to have Unicode when you want ASCII. But if you want to support Unicode, than you don't want an upper boundary!

In my code you absolutely do not want an upper boundary as it is a highscore input and people will be typing in their names which may be using characters that go well above 127! You do realize that there are other characters in the world right and that is the whole point of Unicode?

To set boundaries to ASCII in a Unicode routine doesn't make any sort of sense. At least not for the use I have in my own code example. As soon as someone from another nation, say a French person, types in "é", limiting your characters to ASCII will miss this!

I already posted code... `if(event.keyboard.unichar >= 32) {` And what I posted, works. But feel free to piss around with other methods.

If all you want is ascii, then characters above 127 are extranneous. If you want to piss around with ALLEGRO_USTRs, by all means go ahead, but for someone who only wants ASCII, it is a ton of wasted work. See how that sounds? So piss off. Seems to be your favorite saying, hope you enjoy people saying it to you.