Index du Forum » » Création-Développement

Auteur

Comment servir des device Keyboard et input ??
YesCop
373      

  Posté : 04-11-2019 10:51

Voici le code



Sam Flex 800 Mhz Amiga OS4.1 FE
IDCMP-Key-Mou.txt
/*
** eventloop.c - standard technique to handle IntuiMessages from an IDCMP.
*/
#include <exec/types.h>
#include <intuition/intuition.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/intuition.h>
/* our function prototypes */
BOOL handleIDCMP(struct Window *win, BOOL done);
struct Library *IntuitionBase = NULL;
struct IntuitionIFace *IIntuition = NULL;
/*
** main routine.
** Open required library and window, then process the events from the
** window. Free all resources when done.
*/
int main(int argc, char **argv)
{
BOOL done;
struct Window *win;
IntuitionBase = IExec->OpenLibrary("intuition.library", 50);
IIntuition = (struct IntuitionIFace *)IExec->GetInterface(IntuitionBase, 
"main", 1, NULL); 
if (IIntuition != NULL)
    {
    if (win = IIntuition->OpenWindowTags(NULL,
                         WA_Title,       "Press Keys and Mouse in this 
Window", 
                         WA_Width,       500,
                         WA_Height,      50,
                         WA_Activate,    TRUE,
                         WA_CloseGadget, TRUE,
                         WA_RMBTrap,     TRUE,
                         WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_VANILLAKEY |
                             IDCMP_RAWKEY | IDCMP_DISKINSERTED |
                             IDCMP_DISKREMOVED | IDCMP_MOUSEBUTTONS,
                         TAG_END))
         {
        done = FALSE;
         /* perform this loop until the message handling routine signals
        ** that we are done.
         **
        ** When the Wait() returns, check which signal hit and process
        ** the correct port. There is only one port here, so the test
        ** could be eliminated. If multiple ports were being watched,
        ** the test would become:
         **
        **     signals = Wait( (1L << win1->UserPort->mp_SigBit) |
        **                     (1L << win2->UserPort->mp_SigBit) |
        **                     (1L << win3->UserPort->mp_SigBit))
        **     if (signals & (1L << win1->UserPort->mp_SigBit))
        **         done = handleWin1IDCMP(win1,done);
        **     else if (signals & (1L << 
win2->UserPort->mp_SigBit)) 
        **         done = handleWin2IDCMP(win2,done);
        **     else if (signals & (1L << 
win3->UserPort->mp_SigBit)) 
        **         done = handleWin3IDCMP(win3,done);
         **
        ** Note that these could all call the same routine with different
        ** window pointers (if the handling was identical).
         **
        ** handleIDCMP() should remove all of the messages from the port.
         */
         while (!done)
             {
             uint32 signals = IExec->Wait(1L << 
win->UserPort->mp_SigBit); 
             if (signals & (1L << win->UserPort->mp_SigBit))
                 done = handleIDCMP(win,done);
             };
        IIntuition->CloseWindow(win);
         }
    }
IExec->DropInterface((struct Interface*)IIntuition);
IExec->CloseLibrary(IntuitionBase);
return 0;
}
/*
** handleIDCMP() - handle all of the messages from an IDCMP.
*/
BOOL handleIDCMP(struct Window *win, BOOL done)
{
struct IntuiMessage *message;
uint16 code;
int16 mousex, mousey;
uint32 class;
/* Remove all of the messages from the port by calling GetMsg()
** until it returns NULL.
**
** The code should be able to handle three cases:
**
** 1. No messages waiting at the port, and the first call to GetMsg()
** returns NULL. In this case the code should do nothing.
**
** 2. A single message waiting. The code should remove the message,
** processes it, and finish.
**
** 3. Multiple messages waiting. The code should process each waiting
** message, and finish.
*/
while (NULL != (message = (struct IntuiMessage 
*)IExec->GetMsg(win->UserPort))) 
    {
    /* It is often convenient to copy the data out of the message.
    ** In many cases, this lets the application reply to the message
    ** quickly. Copying the data is not required, if the code does
    ** not reply to the message until the end of the loop, then
    ** it may directly reference the message information anywhere
    ** before the reply.
    */
    class = message->Class;
    code    = message->Code;
    mousex = message->MouseX;
    mousey = message->MouseY;
    /* The loop should reply as soon as possible. Note that the code
    ** may not reference data in the message after replying to the
    ** message. Thus, the application should not reply to the message
    ** until it is done referencing information in it.
    **
    ** Be sure to reply to every message received with GetMsg().
    */
    IExec->ReplyMsg((struct Message *)message);
    /* The class contains the IDCMP type of the message. */
    switch (class)
        {
        case IDCMP_CLOSEWINDOW:
            done = TRUE;
            break;
        case IDCMP_VANILLAKEY:
            IDOS->Printf("IDCMP_VANILLAKEY (%lc %ld)\\n",code, 
code); 
            break;
        case IDCMP_RAWKEY:
            IDOS->Printf("IDCMP_RAWKEY (%ld)\\n",code);
            break;
        case IDCMP_DISKINSERTED:
            IDOS->Printf("IDCMP_DISKINSERTED\\n");
            break;
        case IDCMP_DISKREMOVED:
            IDOS->Printf("IDCMP_DISKREMOVED\\n");
            break;
        case IDCMP_MOUSEBUTTONS:
            /* the code often contains useful data, such as the ASCII
            ** value (for IDCMP_VANILLAKEY), or the type of button
            ** event here.
            */
            switch (code)
                 {
                 case SELECTUP:
                     IDOS->Printf("SELECTUP 
at %d,%d\\n",mousex,mousey); 
                     break;
                 case SELECTDOWN:
                     IDOS->Printf("SELECTDOWN 
at %d,%d\\n",mousex,mousey); 
                     break;
                 case MENUUP:
                     IDOS->Printf("MENUUP\\n");
                     break;
                 case MENUDOWN:
                     IDOS->Printf("MENUDOWN\\n");
                     break;
                 default:
                     IDOS->Printf("UNKNOWN CODE\\n");
                     break;
                 }
        default:
            IDOS->Printf("Unknown IDCMP message\\n");
            break;
        }
    }
return(done);
}




Cet article provient de Le site des utilisateurs francophones actuels et futurs d'AmigaOS 4.x

https://www.amiga-ng.org/viewtopic.php?topic=2624&forum=14