How to lock camera and volume control when phone is locked When my phone is locked, the camera and volume controls still work which I find strange.

How can I lock these down also, I don't want these controls to be pressed when in my pocket by mistake.
My device doesn't have a separate camera key, so I was able to test my solutions only with volume up and down keys. AutoInput with Tasker (full 7 day trial; userguide) is what you can try. You would either have to buy or enable full trial of former since the solution featuring AutoInput would not work. 

Important: Launch AutoInput and enable its accessibility service. 

For Tasker:


Profile: State &rarr; Display &rarr; Display State &rarr; Is: Off
Task: (Action): 


Plugin &rarr; AutoInput &rarr; Modes


Configuration: 


Key Suppress: Enable
Keys: tick the entries viz. Volume Up, Volume Down and Camera

Timeout: None


Exit task: (Action):


Plugin &rarr; AutoInput &rarr; Modes


Configuration: 


Key Suppress: Disable
Keys: tick the entries viz. Volume Up, Volume Down and Camera

Timeout: None




That did the job in stock Android 6.0.1 in Nexus 6, at least for volume rockers. 



On a rooted Android, you can try Xposed Additions app. It requires a compatible Xposed Framework1.

Instructions:


Launch Xposed Additions &rarr; tap Buttons
Tap Add new key and when the dialog appears press your hardware key once to register it
Tap the newly created entry for the button you pressed earlier
Tap Add new Condition &rarr; Screen Off
Tap the newly created Screen Off entry &rarr; tick Click under Single Actions


Follow the said instructions for the rest of your relevant hardware keys. 

Note: If Ambient Display is enabled, then during the moments when the display lightens up briefly, pressing any of the relevant keys would result in their actual intended effect and not the one the two solutions aim for. 



1  Xposed Framework: Android 4.x, Android 5.x and 6.x