简体   繁体   中英

Do mouseEvent and keyEvent use the same integer codes?

mouseEvent and keyEvent have methods getButton() and getKeyCode() which both return an integer which match a constant of their repective button (like Mouse2). I am writing an input class and would like to know if any of their integers overlap with each other;

ie

getKeyCode() for "C" returns 3

getButton() for "mouse3" also returns 3

They are distinct constant sets in distinct classes so, it is likely that the same values appear in both. You can see the values by yourself by decompiling those classes in your favorite IDE.

Either way, you should NOT write code that relies on wether their values overlap or not .

There is no contract in the javadoc for the actual value, and the point of having constants is that you should not worry about the underlying value. If you rely on the actual value you are doing something wrong.

Yes, some overlap.

As shown here , BUTTON1 from MouseEvent and KEY_LOCATION_STANDARD from KeyEvent are both 1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM