@orgin
Here is the code from the pdf ZeroG mentioned updated for input device:
struct MsgPort *InputMP;
struct IORequest *InputIO;
struct Library *InputBase;
struct InputIFace *IInput;
BOOL InputIO_used = FALSE;
UWORD qualifier;
InputMP = IExec->AllocSysObject(ASOT_PORT, NULL);
if (!InputMP) cleanexit("Cannot create input message port");
InputIO = IExec->AllocSysObjectTags(ASOT_IOREQUEST,
ASOIOR_Size, sizeof(struct IORequest),
ASOIOR_ReplyPort, InputMP,
TAG_DONE);
if (!InputIO) cleanexit("Cannot allocate IORequest");
if (IExec->OpenDevice(INPUTNAME, 0, InputIO, 0))
cleanexit("cannot open input device");
InputBase = (struct Library *)InputIO->io_Device;
IInput = (struct InputIFace *)IExec->GetInterface(InputBase, "main", 1, NULL);
if (!IInput) cleanexit("Cannot obtain input interface");
// ... call input functions, i.e.
qualifier = IInput->PeekQualifier();
/* set this to true if you are using InputIO
InputIO_used = TRUE;
*/
if (InputIO_used)
{
if (!IExec->CheckIO(InputIO))
IExec->AbortIO(InputIO);
IExec->WaitIO(InputIO);
}
IExec->DropInterface((struct Interface *)IInput);
IExec->CloseDevice(InputIO);
IExec->FreeSysObject(ASOT_IOREQUEST, InputIO);
IExec->FreeSysObject(ASOT_PORT, InputMP);
/edit: updated InputIO handling
Edited by Gazelle on 2009/4/18 14:59:57