home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / amigae / e_v3.2a / rkrmsrc / keymap / mapansi.e < prev    next >
Text File  |  1977-12-31  |  3KB  |  100 lines

  1. -> mapansi.e - Converts a string to input events using MapANSI() function.
  2. ->
  3. -> This example will also take the created input events and add them to the
  4. -> input stream using the simple commodities.library function AddIEvents(). 
  5. -> Alternately, you could open the input.device and use the input device
  6. -> command IND_WRITEEVENT to add events to the input stream.
  7.  
  8. ->>> Header (globals)
  9. MODULE 'commodities',
  10.        'keymap',
  11.        'devices/inputevent'
  12.  
  13. ENUM ERR_NONE, ERR_INT, ERR_LIB, ERR_OVER
  14.  
  15. RAISE ERR_LIB IF OpenLibrary()=NIL
  16.  
  17. DEF inputEvent=NIL:PTR TO inputevent
  18. ->>>
  19.  
  20. ->>> PROC main()
  21. PROC main() HANDLE
  22.   DEF string, tmp1, tmp2, i,
  23.       iebuffer[6]:ARRAY  -> Space for two dead keys + 1 key + qualifiers
  24.   openall()
  25.   string:=';String converted to input events and sent to input device\n'
  26.   inputEvent.class:=IECLASS_RAWKEY
  27.   -> Turn each character into an inputevent
  28.   tmp1:=string
  29.   WHILE tmp1[]
  30.     -> Convert one character, use default key map
  31.     i:=MapANSI(tmp1, 1, iebuffer, 3, NIL)
  32.     -> Make sure we start without deadkeys
  33.     inputEvent.prev1downcode:=0
  34.     inputEvent.prev1downqual:=0
  35.     inputEvent.prev2downcode:=0
  36.     inputEvent.prev2downqual:=0
  37.  
  38.     tmp2:=iebuffer
  39.     SELECT i
  40.     CASE -2
  41.       WriteF('Internal error\n')
  42.       Raise(ERR_INT)
  43.     CASE -1
  44.       WriteF('Overflow\n')
  45.       Raise(ERR_OVER)
  46.     CASE 0
  47.       WriteF('Can''t generate code\n')
  48.     CASE 3
  49.       inputEvent.prev2downcode:=tmp2[]++
  50.       inputEvent.prev2downqual:=tmp2[]++
  51.       inputEvent.prev1downcode:=tmp2[]++
  52.       inputEvent.prev1downqual:=tmp2[]++
  53.       inputEvent.code:=tmp2[]++
  54.       inputEvent.qualifier:=tmp2[]
  55.     CASE 2
  56.       inputEvent.prev1downcode:=tmp2[]++
  57.       inputEvent.prev1downqual:=tmp2[]++
  58.       inputEvent.code:=tmp2[]++
  59.       inputEvent.qualifier:=tmp2[]
  60.     CASE 1
  61.       inputEvent.code:=tmp2[]++
  62.       inputEvent.qualifier:=tmp2[]
  63.     ENDSELECT
  64.  
  65.     -> Send the key down event
  66.     AddIEvents(inputEvent)
  67.     -> Create a key up event
  68.     inputEvent.code:=inputEvent.code OR IECODE_UP_PREFIX
  69.     -> Send the key up event
  70.     AddIEvents(inputEvent)
  71.     tmp1++
  72.   ENDWHILE
  73. EXCEPT DO
  74.   closeall()
  75.   SELECT exception
  76.   CASE ERR_INT;   WriteF('Error: MapANSI() internal error\n')
  77.   CASE ERR_LIB;   WriteF('Error: could not open required library\n')
  78.   CASE ERR_OVER;  WriteF('Error: MapANSI() overflow error\n')
  79.   CASE "MEM";     WriteF('Error: ran out of memory\n')
  80.   ENDSELECT
  81. ENDPROC
  82. ->>>
  83.  
  84. ->>> PROC openall()
  85. PROC openall()
  86.   keymapbase:=OpenLibrary('keymap.library', 37)
  87.   cxbase:=OpenLibrary('commodities.library', 37)
  88.   NEW inputEvent
  89. ENDPROC
  90. ->>>
  91.  
  92. ->>> PROC closeall()
  93. PROC closeall()
  94.   IF inputEvent THEN END inputEvent
  95.   IF cxbase THEN CloseLibrary(cxbase)
  96.   IF keymapbase THEN CloseLibrary(keymapbase)
  97. ENDPROC
  98. ->>>
  99.  
  100.