If you want to do it when a PasswordTextBox is on focus for example
(this is from my sign-in page):
passwordTextBox.addKeyPressHandler(new KeyPressHandler() {
public void onKeyPress(KeyPressEvent event) {
if (((int)event.getCharCode()) == 13) { // User hit
"Enter" key
submitForm();
}
}
});