[racket] key event problem
On Wed, Apr 18, 2012 at 11:17, Roelof Wobben <r.wobben at home.nl> wrote:
> Hello,
>
> 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)
> (cond
> [ (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 ?
maybe:
(define (edit e k)
(cond ((key=? "right" k)
(if (zero? (string-length (editor-post e)))
e
<create an updated new editor>))
((key=? "left" k)
(if (zero? (string-length (editor-pre e)))
e
<create an updated new editor>))
...
))
?