I think you should use ALLEGRO_EVENT_KEY_CHAR and then check event.keyboard.keycode.The ALLEGRO_EVENT_KEY_CHAR has a keyboard.repeat field, where the ALLEGRO_EVENT_KEY_DOWN field does not and I don't believe you'll get ALLEGRO_EVENT_KEY_DOWN for repeated keys.

KEY_DOWN and KEY_UP represent a physical key being pressed or released. KEY_CHAR indicates some character has been pressed or repeated.

Note that there is not a 1:1 map between KEY_DOWN and KEY_CHAR. Some characters may take multiple KEY_DOWN events to get triggered. Or one KEY_DOWN could trigger multiple KEY_CHARs (repeats, macros, etc...).

Solution #1: use KEY_CHAR

Solution #2: set a flag when receiving KEY_DOWN and clear it when receiving KEY_UP

Relying on repeating keys isn't generally good practice though. So I'd use #2 if you use events.

Solution #3: use the keyboard state functions instead of keyboard events. This is how Allegro 4 worked.

Small correction to BillyBob's code - al_key_down takes two arguments - an ALLEGRO_KEY_STATE* and an int keycode. Which means you need to also declare an ALLEGRO_KEY_STATE object and use al_get_keyboard_state on it.

Actually I wrote this quickly for a test program I have (pixel perfect collision) and I just needed to move the character (pacman in this test) around until it collides in various ways to see if the codes works.

I just tried setting a flag, and it works, but it seems awful slow at times (I sped up the movement by +2 instead). Especially when drawing rectangles. I draw a rectangle around three bitmaps I am drawing to show the bounding box for collisions and when there is a collision I change the colour of the bounding box from green to red, that really seems to cause a bit of a spike in lag for a moment.

I'm thinking that I may have to ditch the idea of using events altogether or do something differently. This is a pretty simple program.

I just tried setting a flag, and it works, but it seems awful slow at times (I sped up the movement by +2 instead). Especially when drawing rectangles. I draw a rectangle around three bitmaps I am drawing to show the bounding box for collisions and when there is a collision I change the colour of the bounding box from green to red, that really seems to cause a bit of a spike in lag for a moment.

How often do you draw, and what rate is your timer set at? A simple program like that should be ridiculously fast. Show more code.

I haven't tried your new code yet. This works, but lags when you collide a little. Probably my collision code is a little slow, but I couldn't imagine it being THIS slow, it was faster before. I am reading and comparing pixels from the colliding bitmaps, so I am wondering if there is something extra I need to do before reading pixels etc...

Now I'll try out your suggestions. I'm using this as a test project to basically get the hang of programming Allegro 5 before I do anything major.

EDIT: note some comments were left in from allegro 4 and no longer apply. Like testing the pixels in each bitmap, I now just add up the R G B values together and test, the transparent colour is black so if there is no pixels other than black, the colour will still be zero. I am sure this could be done better, but it was changed from allegro 4 on the fly. Also wouldn't mind speeding the code up where it checks the overlap.

Outside of your for loops where you get the pixel values with al_get_pixel, you should lock both of your sprite bitmaps with al_lock_bitmap(sprite1->img , ALLEGRO_LOCK_READONLY , al_get_bitmap_format(sprite1->img) , 0);. That should speed up access to the data. Access to video memory is slow, so that may be your problem, but on the other hand it might slow you down your drawing to use memory bitmaps instead. Don't forget to al_unlock_bitmap when you're done reading pixels.

Edit -If you compare the ALLEGRO_COLOR that you get from al_get_pixel to al_map_rgba(0,0,0,0) it would probably be faster than decomposing the color components. Just declare

for(cy=0; cy < over_height; cy++){for(cx=0; cx < over_width; cx++){// sample a pixel from each object
pixel1 =al_get_pixel(object1->img, (over_left-object1->x)+cx, (over_top-object1->y)+cy);
pixel2 =al_get_pixel(object2->img, (over_left-object2->x)+cx, (over_top-object2->y)+cy);// compare the two pixels. BOTH have to contain a colour other than black (transparent)// for a collision to be flaged. IF either pixel is transparnet than no collision is present.if((pixel1 != trans)&&(pixel2 != trans))returntrue;}}