Have a nosey round the examples folder inside your Max/Cycling74 folder; there’s many midi-synth examples.
A quick fix for this is to use the note-off velocity from your keyboard (I assume you mean an external midi keyboard); when the key is released it sends a velocity of zero. Use [sel 0]-> message[0 50]->[line]->[*~] and multiply the output of your oscillator or sound source by this ramp.
Also look at the helpfile for [makenote] and the handy little "See Also" box in the helpfiles.
Definitely have a look to see how the examples achieve this. You might also want to look at other midi processing objects like [stripnote] (in conjunction with [sel 0] for note-offs) and envelope generators like [function] and [adsr~].