hgs was hinting about how to do it, and I will give a little clearer hint, I hope. Your code will need to be something like,
Code:
this.pirate add Keylistener: declare procedure KeyPressed, with parameter KeyEvent w
do in order
Here is where you will need to choose whether to move the pirate or not.
You will need to choose from the list(image attached) one that will let you choose "if ___ is TRUE do ___" and "if ___ is FALSE do ___ (in your case, nothing)"
If my hint wasn't good enough, just post another message, and I will tell you the WHOLE step-by-step (maybe).
Hope this helps!