Cabbage Logo
Back to Cabbage Site

Capturing key events

I’m trying to create a tool that will allow a user to click on the screen to draw boxes, and would like to use key events to control how the boxes are created.

Only trouble is I can read from the three identifiers for key entry to get their value, but no matter what I do I get an error warning from cabbage in the form of a beep.

Where exactly is this warning coming from and how do I get rid of it?

I"m pretty sure that’s a system beep no? Can you post a simple example? Also note that key presses like this may be rendered completely useless if users were to load the instrument in a DAW as most of them steal keypresses for DAW functions.

It’s for the bounding box Toolset, so this part will never be used outside of Cabbage. I’ll get you the example tonight… I’m at the job that pays me money…

Sorry this took so long…

<Cabbage>
form caption("Untitled") size(998, 401), guiMode("queue"), pluginId("def1") bundle("MiniMoogPanel2.png")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

;instrument will be triggered by keyboard widget
instr 1
    iW cabbageGet "form", "width"
    iH cabbageGet "form", "height"
    
    prints "iW: %d iH %d\n", iW, iH
    
    SStr = sprintf("bounds(0, 0, %d, %d) file(\"MiniMoogPanel2.png\")", iW, iH)
    prints "%s\n", SStr
    cabbageCreate "image", SStr
    
    kMouseX chnget "MOUSE_X"
    kMouseY chnget "MOUSE_Y"
    kMouseDownLeft chnget "MOUSE_DOWN_LEFT"
    
    kKeyPressed chnget "KEY_PRESSED"
    kKeyDown chnget "KEY_DOWN"
    SKeyModifiers chnget "KEY_MODIFIERS"
    
    if changed(kMouseDownLeft) == 1 && kMouseDownLeft == 1 then
        printks "mousex: %d mousey: %d (%f)\n", 0, kMouseX, kMouseY, kMouseX / iW
    endif
    
    if changed(kKeyPressed, kKeyDown) == 1 then
        printks "pressed: %d down: %d modifiers: %s\n", 0, kKeyPressed, kKeyDown, SKeyModifiers
    endif
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
i 1 0 -1
f0 z
</CsScore>
</CsoundSynthesizer>

I’m not getting any such beep here. But then again, I have my sound effects turned down :rofl:

Some moments later…
…when I turn them back up I can here it. I’m not sure why this happens, but I will take a look.