<a href="http://www.google.com" id="testlink">CatchMe</a>
$('#testlink').attr("rel", $('#testlink').attr("href"));
$('#testlink').attr("href","");
$('#testlink').keydown(function(event) {
if (event.keyCode == '13') {
alert("Don't you dare!");
}
if (event.keyCode == '71') {
location.href=$('#testlink').attr("rel");
}
});
This code removes the href (stores it in rel). Now you can catch the keydowns. You can respond to the enter key (13) however you like (alert in this case). Afterwards you can let the browser follow the link after all, if you want. In this example however, I only let the browser follow the link when the 'g' key (code 71) is pressed.
Note that this also works when the href value is like 'javascript:alert("blah")'.
Edit: this is a lot easier however (inspired by the answer to this question):
$('#testlink').click(function () {alert("hi"); return false; });
(return true if you do want the link to be followed after the alert)