I'm running Windows 7 and was curious if there was any way to use Java to tell when a button on the apple headphones was pressed. I searched around and didn't find much. If anyone knows anything, help would be much appreciated, thanks in advance!
Asked
Active
Viewed 930 times
2
-
How are the headphones plugged ? USB ? Jack ? – Florent Bayle Aug 27 '14 at 14:50
-
They're plugged into the headphone jack. – Notorio Aug 27 '14 at 14:53
-
it must change the system volume level. Therefore you can try to access that data through some api. Look at this http://stackoverflow.com/questions/4211439/getting-the-system-audio-levels-in-java – Thusitha Thilina Dayaratne Aug 27 '14 at 14:54
-
Is it just a volume control, or does the button usually do other things? – Reinstate Monica -- notmaynard Aug 27 '14 at 14:56
-
You may check the `toString` result of `KeyEvent`. In my JRE version it contains something like `…KEY_RELEASED,…,rawCode=174,…,scancode=46…` or `…KEY_RELEASED,…,rawCode=175,…,scancode=48…` for volume up and down. But there is no standard API for getting `rawCode` or `scanCode` so you will have to either use Reflection or parse the `String` representation of the `KeyEvent`. Either way is non-standard and ugly but I don’t know of any alternative. – Holger Aug 27 '14 at 17:15