KeyListener Limiting to Alphanumeric

I’m trying to create a keylistener that will only allow alphanumeric input.

I have done this before but cannot remember how.

for some reason getKeyCode() continues to give me 0 regardless of what key is pressed. is this normal? I feel like in the past all i did was use an if statement something like:

if(e.getKeyCode() >= KeyEvent.VK_A && e.getKeyCode() >= KeyEvent.VK_Z)
do something

any ideas?

my mistake. i had all the code in the keyTyped method. should have been in the keyPressed method.