home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / pocketbk / developmen / oplexamp / CAPTURE.TXT < prev    next >
Text File  |  1994-06-14  |  1KB  |  36 lines

  1. >       Does anyone know how I can get a program to run when a certain key
  2. > is pressed?  Not an application, just a normal program written in OPL.
  3. > I want to run the program when I press the Psion-Shift-1 key.
  4.  
  5. Briefly, you need to have *two* programs: one that is the real program 
  6. that you want to run, and another that sits in the background, waiting 
  7. for this particular keypress.
  8.  
  9. In order to receive a keypress even when you are in background, you have 
  10. to "capture" that keypress, using call($c58d).  This takes two 
  11. parameters, in the BX and CX "registers".  The BX value is the keycode 
  12. you want to capture, and the CX is regarded as split into CL (the low 
  13. byte) and CH (the high byte).  To cut a long story short, set CH as $e in 
  14. all cases.  Set CL to be the modifiers you want to match.
  15.  
  16. In your case, there is the additional complication that Psion-1 generates 
  17. the "unexpected" value (W_KEY_OFF) of $2003.
  18.  
  19. Thus to capture Psion-Shift-1, put the following into your program:
  20.  
  21.     if call($c58d,$2003,$e0a)
  22.       print "Failed to capure key"
  23.     endif
  24.     As a simple example, write a 9 line program which starts out as above 
  25. and then has
  26.  
  27.     while 1
  28.       get
  29.       beep 5,320
  30.     endwh
  31.  
  32. Run it, press a few keys, hear the beeps, then task away and try 
  33. Shift-Psion-1.
  34.  
  35. Regards, DavidW
  36.