Flash to simulate SMS (text message) input

Hi people, need some help to develop a flash file that can simulate a sms (text message) input like how you will write a message with your mobile phone.

For example pressing the num “1” once, will give u “a”, twice will give u “b”, and trice will give u “c” etc.

I have an onscreen number pad, so user click the button “1” will give u “a”, twice will give u “b” and etc

Problem is how can I detect the mouse to be how many click before they chunk out a alphabet. Also not forgetting some key like “7” need to test for 4 hit (P,Q,R,S).

Any idea how should I do it?

Thanks in advance!