[racket] key event problem

From: Roelof Wobben (r.wobben at home.nl)
Date: Wed Apr 18 05:17:44 EDT 2012


I try to make a function which controls the key-events.

The function does only have to react on backspace , left , right .
Give no reaction on tab , rubout or the other keys with a length more 
then 1.
When given another key with length 1 it has to insert the key.

So i thought this would work :

(define (edit e k)
      [  (and(key=? "right" k) (> (string-length (editor-post e)) 0)) 
(make-editor(string-append (editor-pre e) (string-first (editor-post e) 
)) (string-rest (editor-post e) ))]
      [  (and(key=? "left" k) (> (string-length (editor-pre e)) 0)) 
(make-editor ( string-remove-last (editor-pre e) ) (string-append 
(string-last(editor-pre e))  (editor-post e)))]
      [  (and (key=? "\b" k) (> (string-length (editor-pre e)) 0)) 
(make-editor (string-remove-last (editor-pre e)) (editor-post e))]
      [  (not ( or (key=? "\t" k ) (key=? "\u007F" k) (key=? "right" 
k))) ( string-append (editor-pre e) k)]
      [else e]

but now when someone press the right-key the first get executed but also 
the not rule.
I thought that cond works if one rule is true the other gets ignored. 
But it looks like that's not true.

Now my question is : how can I take care that all the other key's with 
length 1 except backspace, tab, and rubout get's executed ?


Posted on the users mailing list.