Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Keyboard & mouse not working on ubuntu 11.10

This thread is locked; no one can reply to it. rss feed Print
Keyboard & mouse not working on ubuntu 11.10
Losiowaty
Member #13,930
January 2012

Hi everybody,
For my class assignment I had to write a paint-like program in C++ using Allegro. I had to use 4.2 version, as all assignments need to be run on class computer with Solaris 6 and Allegro4.2 installed.
Anyhow - to the problem : When I had a piece of working code I tested in on the target machine and everything worked fine (i.e. drawing lines and shapes with mouse, choosing tools with keys), but after I added some lines the program stopped responding to mouse and keyboard(mouse is also not shown), both on my Ubuntu 11.10 and target Solaris... It works fine od Windows7, the install_mouse/keyboard() functions return succes, mouse/keyboard_needs_poll return false. I tried commenting out a piece of code so that it would only print info to terminal when user pressed a button, but no luck.

#SelectExpand
1 2#include <allegro.h> 3#include <vector> 4#include <time.h> 5#include <sstream> 6 7int main(){ 8 9//all the variables are defined here 10 allegro_init(); 11 install_mouse(); 12 install_timer(); 13 install_keyboard(); 14 set_color_depth(32); 15 gfxStatus = set_gfx_mode( GFX_AUTODETECT_WINDOWED,800,600,0,0); 16 if (gfxStatus == 0) { 17 clear_to_color(screen, WHITE); 18 gui_fg_color = D_GREY; 19 gui_bg_color = L_GREY; 20 21 srand(time(NULL)); 22 23 for (int i = 0; i < 11; i++) historia[i] = create_bitmap(SCREEN_W, SCREEN_H - 50); 24 25 show_mouse(screen); 26 while (!exit){ //petla glowna 27 if (key[KEY_ESC]) { //wyjscie 28 //a lot of other key options here, basically doing the same -> changing current tool 29 if ((mouse_b & (1 | 2)) && (mouse_y > 50)) { 30 //mouse action here 31 } else if ((mouse_b & (1 | 2)) && (mouse_y < 50)) { //user dziala na 32 //special mouse action here 33} //koniec if od myszki 34 } //koniec petli glownej 35 } else { //koniec if gfxStatus 36 std::cerr << "Allegro error!\n" << allegro_error << "\n"; 37 } 38 39 40 return 0; 41} 42END_OF_MAIN(); ///Makro z allegro

While writing this post I had an idea -> could it be that time.h is messing up with allegros timer?

Anyway, I'd be gratefull for any help.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

It may have something to do with resource locks of some sort - do you ever use acquire_screen / release_screen at all? If you acquire and don't release, it may block input. Do you ever call read_key? That function blocks until there is a keypress in the queue. We probably need to see more code - and if you post more, try to fix the formatting first (your indentation is not consistent).

Losiowaty
Member #13,930
January 2012

I solved the issue ;] The problem was non-allegro. I simply called sleep(200); thinkning that it took miliseconds, when it takes seconds, so it stopped my program for about 3 minutes! My bad here ;]

Anyway - thanks for the replay and ideas!

Go to: