Notifications
Clear all

[Closed] keystroke callbacks

Could someone kindly tell me the best way to initiate an event from a keyboard stroke, such as pressing the space bar?
My dot net knowledge is rusty and I have trouble with the poor mxs documentation. Thank you all for your attention.

3 Replies

You didn’t specify where you need to catch that event, but here’s an example for the textbox


try (destroydialog X ) catch ()
rollout X "" width:250 (

    edittext mxsTextbox ""
    dotnetcontrol dotnetTextbox "system.windows.forms.textbox"
    dotnetcontrol cc "UserControl" width:224 height:20 offset:[0,10]
    
    local mxsText = ""
    
    fn onKeyPress s ev = (
        
        if ev.keyCode == ev.keyCode.Space do format "User control space pressed!
"
        
    )
        
    on x open do (
        
        cc.controls.add (dotnetobject "system.windows.forms.textbox")
        dotNet.addEventHandler cc.controls.item[0] "keyUp" onKeyPress
        dotNet.setLifetimeControl cc.controls.item[0] #dotnet
        
        cc.controls.item[0].width = 224
        
    )
    
    
    on mxsTextbox changed txt do (
        
        for i=1 to txt.count do (
            
            if txt[i] != mxsText[i] do (
                
                if txt[i] == " " then format "edittext space pressed!
" else exit
                
            )
            
        )

        mxsText = txt
        
    )
    
    on dotnetTextbox keyUp ev do (
        
        if ev.keyCode == ev.keyCode.Space do format "Dotnetcontrol space pressed!
"
            
    )

)
createDialog X pos:[100,100]

Thanks very much for that.
I actually just need the control on a button, so that when I press the button, another action will hap;pen when spacebar is pressed.
It’s nothing to do with text input… It’s to do with activating a movement recorder I’ve written. ( to start and stop the recording as I move the mouse around)
Do I need a dot net form control or what?
Thank you once again

Same story.
You can run showevents <yourDotNetControlHere> to get a list of available events


try (destroydialog X ) catch ()
rollout X "" (

    dotnetcontrol btn "system.windows.forms.button"
    
    on btn keyup s ev do (
        
        if ev.keyCode == ev.keyCode.space then (
            
            format "Space pressed!
"
             
        )        
        
    )

)
createDialog X pos:[100,100]