Launch a specific app functionality clicking a button


Hi !

I need help please....
Is it possible to launch automatically a function of my app which i developed, when i press a specific smartphone button, located on the side of the phone ?

Imagine a new press button on your phone (not standard), how can i program a specific action about it?

Does it work if the phone is locked ? it's possible ?

Many thanks ;)