Binding a key to a command is fairly straightforward. Basically, you just open your console and type bind key command. Keep in mind that you are 99% of the time binding a console command, so be sure to use the sm_ version of it (ie. sm_menu). There are a few quirks about binding keys though.
An important thing to keep in mind is that if your game crashes, you will lose ALL the binds you have made since the last time it was closed normally. So, if you go setting up 50 binds and then your game crashes, don't say I didn't warn you. It is possible to place all of your binds into a cfg file, but I'm not getting into that discussion here. I'm sure you can google it.
Another thing that sometimes drives me nuts is trying to figure out what HL2 names the keys on my keyboard and my XBox controller.
You can see a full listing on this Key List website.
I know it says it's for Team Fortress 2™ but, I think for all Valve® based games or games that use the Source® engine, the key bindings are the same, if not very similar. At least for keyboard and mouse users.
Bindable Xbox 360 Controller buttons
S1_UP
S1_DOWN
S1_LEFT
S1_RIGHT
STICK1
S2_UP
S2_DOWN
S2_LEFT
S2_RIGHT
STICK2
UP
DOWN
LEFT
RIGHT
BACK
START
A_BUTTON
B_BUTTON
X_BUTTON
Y_BUTTON
L_SHOULDER
R_SHOULDER
L_TRIGGER
R_TRIGGER
Your personal Key Bind Listings
If you had forgotten if a specific key is bound to something and don't just want to press it anyway to find out what it does, just in case, then this where a few of these commands come in handy. All you have to do to see what your F key is bound to (if anything) is type bind f in your console. If it is bound, it will tell you what it is bound to. If it is not bound, it will tell you.
You can also type in key_listboundkeys in console. This will show you ALL of they keys you currently have bound.
If you want to unbind a key (remove its functionality), you can use the unbind command. For instance, say I want my C key to no longer save my checkpoints. I would type unbind c into console. DO NOT USE UNBINDALL! If you do that, you will lose ALL of your binds!
Do I need to use Quotes?
Well, it depends. If the command use you are wanting requires a parameter, then yes. If you are 'chaining' commands together into one bind, yes. Otherwise, you do not need quotes. Here are a few examples.
I want to bind my C key to set my checkpoint. OK, this does not require any additional input, so no quotes are needed.
bind c sm_cp
I want to bind my N key so that it sets my model to superman. This is indeed possible, but you will need to use quotes. Why? Because the command requires that you specify which model you want.
bind n "sm_model superman"
I want my 9 key that colors my prop that I am looking at blue, sets its alpha to 180, and sets the rendering fx to #1. This is also very doable. You just need to seperate the command with a semicolon (;) and put the entire command in quotes. It is probably a good idea to include a 'wait' command inbetween commands though. The 'wait' command just tells it to wait a game frame before running the next command in line. NOTE - do not put too many things into one key bind. Sometimes the system will think you are spamming and will not run all of the commands.
bind 9 "sm_setcolor 0 0 255;wait;sm_setalpha 180;wait;sm_setfx 1"
Binding chat commands
I want to bind my L key to make me say "You sure are sexy!!" in chat. Well, here is that one...
bind l "say You sure are sexy!!"
I want to bind my T key to use the 'timeleft' chat trigger. No problem!
bind t "say timeleft"
Other useful binds
Well, if I had enough keys, I would probably bind every key I had to a command. I don't, so here are some that you probably want to bind a key to. Feel free to use any key of your choosing. These are just what I use. Just don't use a key that you are already using for something else.
bind k sm_kill
bind c sm_cp
bind u sm_ucp
bind a sm_acp
bind g sm_go
bind m sm_menu
bind v thirdperson
bind b firstperson
bind del sm_deleteprop
bind kp_end sm_grab
bind kp_home sm_lengthen
bind kp_leftarrow sm_shorten