1

我的最终目标是有一个处理程序,如果我按下一个键,它就会做一些事情,例如#"1"

我一直在阅读R3 视图 - 事件处理文档,并尝试在 R3 视图中运行代码,但没有得到任何结果。这是我复制的处理程序:

my-handler: [
    name: 'my-handler
    priority: 50
    handler: func [event] [
        print ["event:" event/type event/offset]
        if switch event/type [
            close [true]
            key [event/key = escape]
        ] [
            unhandle-events self
            unview event/window
            quit
        ]
        show event/window
        none
    ]
]

我已经尝试了两种方法来运行事件处理程序,但没有结果:

handle-events my-handler
view layout [button]

view/options layout [button] [handler: my-handler]

我不知道该怎么做,有人能指出我正确的方向吗?

这是我为密钥制作处理程序的尝试:

view/options [button] [
    handler: [
        name: 'my-handler 
        priority: 50 
        handler: func [event] [
            if (event/key = #"1") [print "hi"]
        ]
    ]
]

据我所知,它没有做任何事情......

4

1 回答 1

0

这应该适用于已发布的 saphirion r3-gui,但非常粗糙。

load-gui  

ending: :halt  ; :quit  

base-handler: context [ ; we overwrite the default
    do-event: func [event] [
    ;   print "(Missing event handler)"
        if switch event/type [
           key [  ; this we add
            ; if event/key = #"1" [print "hi"]
              escape = probe event/key
           ] 
           close [ true]
        ] [
           unhandle-events self
           unview event/window
           ending
        ]
        event
    ]
    win-gob: none
    status: 'made
    name: 'no-name
    priority: 0
    about: "Main template for VIEW event handlers."
]

view/options [button] [handler: [] ]; this is not correct, so the base-handler is used
于 2013-09-05T14:26:39.513 回答