rg20+@andrew.cmu.edu (Rick Francis Golembiewski) (11/11/89)
I was looking for code to do the following in C (Lattice) 1> Get the window pointer of the selected window 2> Force a refresh of the screen. 3> How to trap keyboard input? (ie I'de like to have hot keys activate my program). I also had the following questions: What happens when a window is removed from the display list? (ie by just reassigning the pointers). Any Help would be appriciated.
owl@drycas.club.cc.cmu.edu (11/13/89)
In article <YZKoMW600WB5Eu5EkJ@andrew.cmu.edu>, rg20+@andrew.cmu.edu (Rick Francis Golembiewski) writes: >I was looking for code to do the following in C (Lattice) > >1> Get the window pointer of the selected window struct IntuitionBase *IntuitionBase; .. long lock; struct Window *activeWindow; lock = LockIBase(0); activeWindow = IntuitionBase->ActiveWindow; /* Do whatever you want with activeWindow */ UnlockIBase(lock); /* Check usage, my Amiga & RKM are 6000 miles east */ /* Note: activeWindow is now unsafe to use ... */ >2> Force a refresh of the screen. You could always open & immediately close a full screen window (preferably a window with no borders, drag bar, title eetc). With luck, the user won't notice it's appearance & disappearance. >3> How to trap keyboard input? (ie I'de like to have hot keys activate >my program). The following is extracted (and slightly modified) from a program that I've written (you might want to handle the installation & cleanup differently). To set up your input handler: /* Some global vars: static struct Task *me; static struct MsgPort *inputDevPort; static struct IOStdReq *inputRequestBlock; static struct Interrupt handlerStuff; static int inputOpen; int install_handler(void) { /* Install input handler */ me = FindTask(0); inputDevPort = CreatePort(0,0); if (inputDevPort) { if (inputRequestBlock = CreateStdIO(inputDevPort)) { handlerStuff.is_Data = NULL; handlerStuff.is_Code = (void *)handle_input; handlerStuff.is_Node.ln_Pri = 51; if (OpenDevice("input.device", 0, inputRequestBlock, 0) == 0) { inputOpen = TRUE; inputRequestBlock->io_Command = IND_ADDHANDLER; inputRequestBlock->io_Data = (APTR)&handlerStuff; DoIO(inputRequestBlock); return TRUE; } } } return FALSE; } To clean up: void cleanup_handler(void) { if (inputOpen) { inputRequestBlock->io_Command = IND_REMHANDLER; inputRequestBlock->io_Data = (APTR)&handlerStuff; DoIO(inputRequestBlock); CloseDevice(inputRequestBlock); } if (inputRequestBlock) DeleteStdIO(inputRequestBlock); if (inputDevPort) DeletePort(inputDevPort); } And your input handler must be something like this: static long __saveds __asm handle_input(register __a0 struct InputEvent *ev , register __a1 void *dummy) { struct InputEvent *ep, *laste; static struct InputEvent retkey; if (req) /* run down the list of events to see if they pressed the magic key */ for (ep = ev, laste = NULL; ep != NULL; ep = ep->ie_NextEvent) { if (ep->ie_Class == IECLASS_RAWKEY && (ep->ie_Qualifier & AMIGALEFT) && (ep->ie_Code == KEYCODE_V)) /* Checks for Left Amiga-V */ { /* Wake up your task, eg with Signal(me, somesignal) */ /* we can handle this event so take it off the chain */ if (laste == NULL) ev = &retkey; else laste->ie_NextEvent = &retkey; break; } else laste = ep; } /* pass on the pointer to the event */ return (long)ev; } >I also had the following questions: What happens when a window is >removed from the display list? (ie by just reassigning the pointers). No idea ... >Any Help would be appriciated. David Gay dg3i+@andrew.cmu.edu