Cabbage Logo
Back to Cabbage Site

Reading special keys(ctrl, cmd, alt, ect...)

Hi Rory,
Is there a way to read these keys in Cabbage. As the “KEY_PRESSED” channel doesn’t return those, I tried the FLTK opcode FLkeyIn which is supposed to read these keys as well as normal ascii. But it seems maybe like the FLTK is conflicting with Cabbage? It crashed a few times and when it’s running it has to have the separate FLTK pannel up + it still doesn’t return anything.
Is there another way to read special keys?
This is what I tried:

FLpanel "FLkeyIn", 400, 300, -1, -1, 5, 1, 1
FLpanelEnd
FLrun

instr 1
kGain chnget "gain"

kascii   FLkeyIn
ktrig changed kascii
if (kascii > 0) then
  printf "Key Down: %i\n", ktrig, kascii
else
  printf "Key Up: %i\n", ktrig, -kascii
endif

a1 inch 1
a2 inch 2

outs a1*kGain, a2*kGain
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
;starts instrument 1 and runs it for a week
i1 0 [60*60*24*7] 
</CsScore>
</CsoundSynthesizer>

Yikes, I wouldn’t suggest using FLTK with Cabbage at all. I can add a special key modifier channel?

Haha, yeah I guess it’s kinda putting some plastic rims on a Lamborghini. Would be cool to have the special key channel. I’m still on that alternative for zooming in on a soundfiler. I’m using left click and drag to make a selection in the soundfiler( yes, I made my own because I wanted the ability to also “grab” the ends of the selection to only change the in or the out point.) and added right click and drag to zoom and pan.
That’s a painful practice on a laptop with a trackpad, so something like [cmd] + click and drag would be necessary as a letter key will most likely trigger some shortcut in the DAW.
Any chance you’d get involved with reading trackpad gestures :D?

There is a cross platform mouseMagnify() method that can respond to pinch/zoom gestures? But apart from that it would really be a lot of work. If you’re interested, I can look at the pinch/zoom stuff. In the meantime, I’ll add a key modifier channel…

I’ve add a KEY_MODIFIERS reserved channel. It will return a list of Command, Shift, Ctrl, Alt, depending on what was pressed. You should use it in conjunction with the KEY_DOWN as it holds it’s last mods until new ones are pressed.

Perhaps ints are easier than strings? It’s always easier to test numbers? But it also makes the code a little more cryptic?

Seems like the KEY_MODIFIERS channel only returns something when you combine the special key with a normal letter. Also the KEY_DOWN channel doesn’t report the special keys.

instr 1
kGain chnget "gain"

Skeymod         chnget "KEY_MODIFIERS"
keydown         chnget "KEY_DOWN"

if(changed(keydown) == 1 && keydown == 1)then
    printks "Key down\n",0.1
endif
if(changed(keydown) == 1 && keydown == 0)then
    printks "Key up\n",0.1
endif
if(changed(Skeymod) == 1)then
    printks "special key:%s\n",0.1,Skeymod
endif

endin

Good call. I pushed a fix for this now. An event is not send whenever a key modifier is pressed. You’ll need to take it for a test run, I didn’t have time to really try it out. I want to concentrate on the questions you asked about the new Cabbage opcodes…

That works perfectly. Now it’s even easier because the key release is received by this channel as well.