You can get the keycode only in keyup or keydown event. if you are using jQuery event.which will hold the keycode
Charcode / Ascii
Charcode/Ascii is available only in keypress event. If you are in keypress event jQuery event.which will hold the ascii value instead of keycode.
You can easily convert the ascii to character with String.fromCharCode method.
Here is the working jsFiddle