A flexible way is to make your own LyX inset (easier than it sounds). Let's start with the "code" inset that is in LyX's Logical Markup module. If you don't need to customize it, just use the module by going to Document > Settings > Modules and add "Logical Markup". But you sound like you might enjoy customizing it, so let's copy it. Put the following in Document > Settings > Local Layout:
Then click "Validate". Then click OK.
Your new inset "Code" is available in the Edit > Text Style menu.
For more information, see Help > Customization. Read sections 5.2 and 5.3.
To make a shortcut out of it, go to Tools > Preferences > Editing > Shortcuts. Click on "New". For the Function, put
flex-insert "Code". Then choose your key binding.