• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question regarding reflection api and class method overriding.

 
Greenhorn
Posts: 23
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello there I'm new to java world, still learning and trying to understand as much as I can. I'm doing it by practice since I think its the best way. Currently I'm trying to develop app with map my xbox controller to system keyboard and mouse. Using some nice free and open source libraries I almost reach my goal but unfortunately I figured one big problem. To simulate keyboard events I use awt.robot its works as a charm with definied in KeyEvent class values for virtual keys codes but does not work for special keys like Volume_Up and Volume_Down. I did small research and figured thats becouse awt.robot before simulate key stroke do test if key value is declared in KeyEvent class. So my application is limited only for keys codes declared there, I think its big issuse since its very limited compared for example to keys declared in Winuser.h (http://msdn.microsoft.com/pl-pl/library/windows/desktop/dd375731(v=vs.85).aspx). I spent some time to trying obey these issue and belive java reflection could do the trick. All I need is to override awt.Robot method to do not check if keycode is declared in KeyEvent class or I need to override KeyEvent class and add some more keycodes declared there as static ints.

Please if you got idea how this can be done, posts here also if you know any good resource where me, completly begginer could easly learn java reflection api post aswell.
Also another solution with im thinking about is forking openjdk, removing unwanted method (private void checkKeycodeArgument(int keycode) from awt.robot) and build it.

I'm so sorry for my bad english, please understand Im self learned from web.
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a good question. You can't use reflection to add code. Forking would work, but seems like overkill.

I haven't done this, but I'm adding some flags to give this post some extra attention.
 
Bartender
Posts: 1357
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wonder if Danny may have a look at JavaAssist. It's a powerful API to manipulate bytecode, even of existing classes.
I tried it some times ago to generate classes on the fly, not to hack existing ones.
Maybe he can manage to hack KeyEvent class.
 
Bartender
Posts: 543
4
Netbeans IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sounds like a job for AspectJ ;)
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Seems to me that this is only the first problem. The second problem is to get your application to actually do whatever it is that the volume-up and volume-down keys do. That isn't something which applications can normally do, which is why those keys aren't mapped by KeyEvent. In particular (as far as I know) there's nothing in the Java API to do that.
 
Danny Wreczycki
Greenhorn
Posts: 23
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I solved the problem by writing simple dll (invoking sendInput from win api) and using it with JNA. For now its the best solution I managed to work but i kinda do not understand why fuctionality of awt.robot is so limited whenever missing functionality could be easly added.



@Paul Clapham
I understand yours point of view but i belive purpose of awt.robot its not only for controlling Java application writed in AWT/SWING due to facts im able to receives and sends events to robot while application is minimalized or has no focus.
 
Claude Moore
Bartender
Posts: 1357
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Danny, thank you for sharing your solution with us, I'm glad you managed it. About java.awt.Robot, from docs it seems that authors wrote it with automatic-testing of Gui in mind.. maybe they limited it to generate events jre is able to handle...
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have no opinion about the purpose of the Robot class. However it's clear to me that the KeyEvent class is meant to support key events which a Java application can receive. And since the key events you're interested in aren't sent to user applications, it follows that there is no point in having KeyEvent support them.
 
Danny Wreczycki
Greenhorn
Posts: 23
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Claude Moore wrote:Danny, thank you for sharing your solution with us, I'm glad you managed it. About java.awt.Robot, from docs it seems that authors wrote it with automatic-testing of Gui in mind.. maybe they limited it to generate events jre is able to handle...



Nah from decription you can read robot its used to handle native system input events for the purposes of test automation of entire JDK. For my curiosity in my spare time i will fork openJDK remove method with in my opinion couse problems and try results. I can also share native windows dlls with little explanation hows they work for using non supported keycodes by Java just le me know you need it. Cheers.
 
Claude Moore
Bartender
Posts: 1357
39
IBM DB2 Netbeans IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great! Good luck and good work !!
 
Jeanne Boyarsky
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Danny,
Thanks for posting your solution. It's something a lot of don't deal with (ddls) so learning a new technique is great. I've given you a cow.

(and now that there is a solution, I can take my flags away - they served their purpose - giving this thread more attention)
 
reply
    Bookmark Topic Watch Topic
  • New Topic