I'm trying to imitate the way that piano makes a sound and I create a DynamicModule to be the key like the following code:
DynamicModule[{col = Green}, EventHandler[ Dynamic[Graphics[{col, Polygon[{{0, 0}, {1, 0}, {1, 3}, {0.5, 3}, {0.5, 5}, {0, 5}}]}, ImageSize -> Tiny]], {"MouseDown" :> {(col = col /. {Red -> Green, Green -> Red}), EmitSound[Play[(1 - t)*Sin[440 2 Pi t], {t, 0, 1}]]}}, {"MouseUp" :> {(col = col /. {Red -> Green, Green -> Red})}}]] Now it can change color when I press it and play the certain sound. But I want to get it more realistic by starting to weaken the sound that is playing when I release my mouse.How can I do this? Or is there any other methods that can get similar result?