Problems Getting Keyboard Event From text-area

Started by oofoe, December 07, 2015, 03:41:27 PM

Previous topic - Next topic

oofoe

Hi!



I'm trying to wire up a text-area with a keyboard event so I can detect if the user presses the escape key while typing. It works fine for text-field Title (see below), but the handler never gets called for keypresses in Body. I have wired the standard handler into gs:no-action because it either only gets fired on pressing the enter key (text-field) or doesn't have any information about non-textual keys (text-area).



Can anyone point out where I'm going wrong?



Thanks!



(load (append (env "NEWLISPDIR") "/guiserver.lsp"))
(gs:init)

(define (field-key id type code modifiers)
  "( id type code modifiers --) Handler for keyboard."

  (println "Key for " id " " type ", " code " with " modifiers "."))

(define (layout)
  "( --) Layout GUI."

  (gs:text-field 'Title 'gs:no-action 64)
  (gs:key-event  'Title 'field-key)
  (gs:text-area  'Body  'gs:no-action)
  (gs:key-event  'Body  'field-key)
  (gs:frame 'F  0 0  800 600  "Text Keyboard Event Test")
  (gs:set-border-layout 'F)
  (gs:add-to 'F  'Title "north"  'Body "center")
  (gs:set-visible 'F true))

(layout)
(gs:listen)
Testing can show the presence of bugs, but not their absence.

Lutz

#1
The documentation is wrong, gs:key-event will not work for gs:text-area. Use the the normal  action handler forgs:text-area, but it will not work for non-displayable characters.



The same problem occured when I was writing the source editor for newLISP-GS. You can find the code in  newlisp-x.x.x/guiserver/newlisp-edit.lsp.



This editor, created with make-editor-tab (around line 310) uses a gs:text-pane and a user defined editarea-handler (around line 1295) to react to keystrokes. Basically you create your own editable text area and then handle everything in newLISP.

oofoe

#2
Hi! Thanks for the hint! I am working on repurposing the newlisp-edit.lsp code now.



Periodically, you call a function (set-buffer-dirty). I can't seem to find this defined in either newlisp-edit.lsp or guiserver.lsp. Is it something that I need to have?



EDIT: Actually it seems that the function was missing from v10.6.0, upgraded to v10.6.2 and I found it.
Testing can show the presence of bugs, but not their absence.