Here's a conceptual answer. To get a more specific answer, you'll have to provide more specific details.
To produce this functionality, you're going to need to take a look at how you can grab keyboard input. This will be a heavy function of your programming language.
On a low-level application, I would set up timers that watch key-down and key-up (or mouse-up/down) and apply timers run with the input. Then have control logic that decides what the input was based on the button pressed coupled with the timer data.
On a higher-level application, you may have an input library to do most of the work for you. Or you could have functions to parse the input that look for things like a long series of the same input signal observed within some time bounds you declare.
Anyway, like I said at the start. To get a specific answer, please at least explain what programming environment you're dealing with? For example, is this for within an Open-GL context frame?