Aaron
Aaron

Reputation: 2073

What is the difference between keyCode and event.getKeyCode in Android?

In the View.OnKeyListener interface, there is a method defined like this:

abstract boolean onKey(View v, int keyCode, KeyEvent event)

What is the difference between the keyCode paramater, and event.getKeyCode()?

Why is there 2 keyCodes?

Upvotes: 1

Views: 130

Answers (1)

cybersam
cybersam

Reputation: 66989

The keyCode value is the same as the event.getKeyCode() value.

The KeyEvent contains full information about the key event, including the key code that caused the event.

I suspect that the keyCode parameter was included in the onKey() method signature because it just made sense to include the most salient information. Also, there are probably a lot of callback implementations that only need the key code.

Upvotes: 2

Related Questions