home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fred Fish Collection 1.5
/
ffcollection-1-5-1992-11.iso
/
ff_disks
/
200-299
/
ff229.lzh
/
LeftyMouse
/
LeftyMouse.c
< prev
next >
Wrap
C/C++ Source or Header
|
1989-07-20
|
5KB
|
111 lines
/*****************************************************************
*
* LeftyMouse - make your Amiga ambidextrous
*
* This program will make your mouse left-handed by installing
* an input handler which swaps the functions of the left
* and right mouse buttons.
*
*****************************************************************/
#include <intuition/intuitionbase.h>
#include <devices/input.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#define PORTNAME "-<:RBE_Lefty:>-"
struct Interrupt handlerptr; /* interrupt struct to install handler */
struct MsgPort *inputport, *replyport; /* msg ports for communications */
struct IOStdReq *inputreq; /* IO request for input device */
struct Message kill; /* message to kill if already running */
extern struct IntuitionBase *IntuitionBase;
extern void hndstub(); /* assembly interface stub */
struct InputEvent *hndcode(struct InputEvent *,int); /* input handler func */
void _main() /* name is _main() not main() to save space (Lattice) */
{
inputport = FindPort(PORTNAME); /* does port already exist - */
if (inputport == NULL) /* is program already running? */
{ /* no - install input handler */
IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0);
inputport = CreatePort(PORTNAME,0); /* make port for IO request */
if (IntuitionBase== NULL || inputport==NULL)
exit(20); /* bomb if can't open */
inputreq = CreateStdIO(inputport); /* open IO request */
if (inputreq == NULL)
exit(21); /* bomb if can't open */
if (OpenDevice("input.device",0,(struct IORequest *)inputreq,0) != NULL)
exit(22); /* bomb if can't open input device */
handlerptr.is_Code = hndstub; /* set up interrupt struct to */
handlerptr.is_Data = NULL; /* install input handler */
handlerptr.is_Node.ln_Pri = 127; /* maximum priority (I think) */
inputreq->io_Command = IND_ADDHANDLER;
inputreq->io_Data = (APTR)&handlerptr; /* IO request to input device to */
DoIO((struct IORequest *)inputreq); /* install input handler */
/* At this point, the input handler is installed and doing its thing.
However, we can't leave now because the handler itself would also
be unloaded. So, we will wait for any message (or possibly forever).
If we get a message we will de-install the handler and leave. */
ReplyMsg(WaitPort(inputport)); /* wait for any message */
inputreq->io_Command = IND_REMHANDLER; /* start packing up */
DoIO((struct IORequest *)inputreq); /* remove input handler */
CloseDevice((struct IORequest *)inputreq); /* close and delete */
DeleteStdIO(inputreq); /* everything we opened */
DeletePort(inputport); /* and allocated */
CloseLibrary((struct Library *)IntuitionBase);
exit(0); /* now we leave! */
}
else /* program already running - send message to kill it */
{
replyport = CreatePort(0,0); /* create reply port for kill msg */
if (replyport == NULL)
exit(20); /* bomb if can't create */
kill.mn_ReplyPort = replyport;
kill.mn_Length = 0;
PutMsg(inputport,&kill); /* send kill msg to program already running */
while(WaitPort(replyport) != &kill) /* wait for reply */
{}
DeletePort(replyport); /* clean up */
exit(100); /* bye! */
}
}
/* This is the actual input handler code. It is called by the assembly
stub hndstub(), which is called whenever there is an input event */
struct InputEvent *hndcode(ie,data)
register struct InputEvent *ie;
int data;
{
register unsigned short x; /* to hold input event code */
register struct InputEvent *e;
e = ie;
do
{
/* is event a mouse button? */
if (e->ie_Class==IECLASS_RAWMOUSE && e->ie_Code!=IECODE_NOBUTTON)
{
x = e->ie_Code & 0x007f; /* mask off IECODE_UP_PREFIX for now */
/* swap button codes, and put back IECODE_UP_PREFIX bit setting */
if (x == IECODE_LBUTTON)
e->ie_Code = IECODE_RBUTTON | (e->ie_Code & IECODE_UP_PREFIX);
else if (x == IECODE_RBUTTON)
e->ie_Code = IECODE_LBUTTON | (e->ie_Code & IECODE_UP_PREFIX);
}
e = e->ie_NextEvent;
} while (e != NULL); /* go thru entire event list */
return(ie); /* pass event(s) on down the line */
}
void MemCleanup() {} /* dummy function to save space (Lattice) */