Thread: Allegro: mouse & keyboard

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    129

    Allegro: mouse & keyboard

    A

    Situation: User is pressing mouse button to draw tiles on the screen. it must not print those if mouse_y > x

    Piece of cake you say. I also believe that I do everything necessary, but if the user is a real idiot and pulls the mouse very quickly under the limit it will draw those tile under x.

    Code:
    while(!kbhit())
    {
    ...
    	if(mouse_b & 1)
    	{
    		rest(10);  //  Helps a bit, but stil...
    		/*	Draw & set a tile	*/
    		if((mouse_x < mapX*PCX_X) && (mouse_y < mapY*PCX_Y))
    		{
    			scare_mouse();
    			map.SetTile(mouse_x/PCX_X, mouse_y/PCX_Y, (TILE)tile); // just an insertion to an array
    			map.UpdateTile(mouse_x/PCX_X, mouse_y/PCX_Y);  // -> blit
    			unscare_mouse();
    		}
    ...
    }

    B

    How to get other than US-layout for the keyboard? (And how to work with that `install_keyboard_hooks()'?)
    Last edited by kooma; 01-01-2002 at 04:38 AM.

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    375
    A .
    Ah yes, this is a case where the mouse coordinates can sometimes update faster than the code can use the ones it thinks they are. This is solved by treating mouse_x and mouse_y as a poll value. Then you make your own variables for keeping track of what you are doing with the mouse.

    ie.


    PHP Code:
    int mymousexmymouxey;
    while(!
    kbhit())
    {
    ...
        if(
    mouse_b 1)
        {
            
    mymousex=mouse_x// as of the button press.
            
    mymousey=mouse_y// as of the button press.
            /*    Draw & set a tile    */
            
    if((mymousex mapX*PCX_X) && (mymousey mapY*PCX_Y))
            {
                
    scare_mouse();
                
    map.SetTile(mymousex/PCX_Xmymousey/PCX_Y, (TILE)tile); // just an insertion to an array
                
    map.UpdateTile(mymousex/PCX_Xmymousey/PCX_Y);  // -> blit
                
    unscare_mouse();
            }
    ...

    B .
    EDIT: See next post.


    As for install_keyboard_hooks(), I would not recommend using it really, for simplicities sake. If you would rather use another keyboard handler, just don't use the install_keyboard() function, but rather take care of the keyboard stuff as you normally would with whatever handler you choose.

    -Justin
    Last edited by Justin W; 01-01-2002 at 03:37 PM.
    Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    375
    Oh wait, here's the function to set the keyboard layout! :
    void set_config_id(const char *section, const char *name, int val);

    Look it up under the "configuration" docs. Sorry about my ignorance in my last post.

    If you don't have the keyboard config file, please download this: http://www.envy.nu/springsoft/keyconf.zip ~ 190kb
    Last edited by Justin W; 01-01-2002 at 03:47 PM.
    Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/

  4. #4
    Registered User
    Join Date
    Aug 2001
    Posts
    129
    Ah, just what I need. But what does that hookey-thing does and why to avoid it?

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    375
    install_keyboard_hooks() is simple and complex. It allows you to use your own keyboard handler. Unfortunately, that means you gotta make your own keyboard handler. Another recent poster needs this to avoid using DirectX. He wants to just use Win32 API. Thus, (as far as I know), he has to write his own message processing loop, tie it into Allegro, then "hook" it into the Allegro keyboard functions.

    It really isn't all that bad, but it will take much more setup work. I suppose if you were hooking in another keyboard handler, it wouldn't be so bad, of course (like DirectInput).

    Glad that other stuff helped.

    -Justin
    Last edited by Justin W; 01-02-2002 at 07:59 PM.
    Allegro precompiled Installer for Dev-C++, MSVC, and Borland: http://galileo.spaceports.com/~springs/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Detecting keyboard and mouse in linux
    By sameer.nalwade in forum C Programming
    Replies: 3
    Last Post: 11-22-2008, 04:24 AM
  2. how to handle keyboard and mouse events for all windows
    By manav-II in forum Windows Programming
    Replies: 3
    Last Post: 08-25-2008, 09:03 AM
  3. GLUT keyboard and mouse func separated
    By krappa in forum Game Programming
    Replies: 1
    Last Post: 04-20-2005, 06:27 PM
  4. Game Design Topic #2 - Keyboard or Mouse?
    By TechWins in forum Game Programming
    Replies: 4
    Last Post: 10-08-2002, 03:34 PM
  5. Replies: 0
    Last Post: 09-08-2001, 06:51 AM