Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!silver!sl161022 From: sl161022@silver.bacs.indiana.edu Newsgroups: comp.sys.mac.programmer Subject: Re: VBL Tasks Message-ID: <99000007@silver> Date: 13 Feb 89 15:36:00 GMT References: <4398@hubcap.UUCP> Organization: Indiana University CSCI, Bloomington Lines: 71 Nf-ID: #R:hubcap.UUCP:-439800:silver:99000007:000:3154 Nf-From: silver.bacs.indiana.edu!sl161022 Feb 13 10:36:00 1989 "VInstall and i understand about setting up a VBLTask record. However, what "if the procedure I install needs to be called only when a certain key combo "is hit? Does it have to scan the event queue or something? "I want it running all the time in the background. Actually, another way to do this (and the way I use to do a similar thing) is to install a patch for _GetOSEvent, which is called quite frequently. In fact, whenever the Finder, the running application, or any DA is ready to respond to an event, it will call either _GetNextEvent (which goes through the Toolbox Event Manager) or _GetOSEvent (which goes directly through the Operating System.) Since _GetNextEvent calls _GetOSEvent, you can patch _GetOSEvent and you'll be essentially guaranteed access to any keypress, and you can then do whatever you want. Of course, I do program in assembly language, where one has direct control of the registers. (_GetOSEvent passes and returns parameters in A0 and D0.) I am not certain how a high level language gets access to the same parameters. Anyway, in assembly language, it looks something like. . . ; the initial code to install your background routine: push.l A4 ;we'll be using this, so save it push.l #'blah' ;fetch the background routine push.w #0 ;(push = move ?,-(SP)) _GetResource ;resource handle still on stack move.l (SP),A4 ;let A4 point to our routine, and move.l (A4),A4 ; detach resource, just to keep it safe _DetachResource move.w #$A031,D0 ;$A031 is the trap code of _GetOSEvent _GetTrapAddress ;A0 <- address of "old" GetOSEvent routine move.l A0,OldGetOS(?) ;save this address, we'll need it later move.w #$A031,D0 ;and now we'll redirect _GetOSEvent to move.l A4,A0 ; my replacement routine _SetTrapAddress ;ta da pop.l A4 ;restore old value of A4 . . . ; the replacement routine, which is a resource ('blah' #0) with its ; resSysHeap and resLocked attributes set (important!!) Beginning push.l A0 ;we'll need pointer to event record later move.l OldGetOS(?),A1 ;call original routine (it's as if we're jsr (A1) ; not even here) pop.l A0 ;we now have access to event push.l D0 ;better save D0, caller is expecting it . . . ;do whatever you want based on the event pop.l D0 ;restore D0 rts The chore of translating this into your language of choice is up to you, but I think this will accomplish what you're after. __________________________________________________________________ "May the forces of evil become confused on the way to your house." Sincerely, -- George Carlin Phaedrus (aka Colin Klipsch) sl161022@silver.bacs.indiana.edu Indiana University at Bloomington