Share My Creation [b4x] Add logging and try catch to your methods - Hot key

Hi all.

First off blame @Roycefer for this. :D:rolleyes::confused:o_O:);)

This started out as a way to learn how to intercept hot keys. I used @Roycefer jNativeHook lib for that. It worked pretty well but in my research I found @Roycefer jAWTRobot lib. hhhmmm, what can I do with these 2 libs together?

So in the end this is what you get. A b4j console app that will paste code into your b4x project depending on the sub.

Remember to unzip the libs.zip and put in your additional lib folder.

So to use, highlight the sub line:

upload_2016-10-11_11-31-44.png


And copy to your clip board

SHIFT-CTRL-E will get you:
B4X:
Log("**********************************")
Log("Method: ime_heightchanged")
Log("NewHeight: " & NewHeight) 'ignore
Log("OldHeight: " & OldHeight) 'ignore
Log("**********************************")

SHIFT-CTRL-R will get you:
B4X:
#if debug
Log("**********************************")
Log("Method: ime_heightchanged")
Log("NewHeight: " & NewHeight) 'ignore
Log("OldHeight: " & OldHeight) 'ignore
Log("**********************************")
#end if

SHIFT-CTRL-W will get you:
B4X:
Try

Catch
     Log("ime_heightchanged: " & LastException)
End Try

SHIFT-CTRL-E will get you:
B4X:
Log("**********************************")
Log("Method: ime_heightchanged")
Log("NewHeight: " & NewHeight) 'ignore
Log("OldHeight: " & OldHeight) 'ignore
Log("**********************************")

Try

Catch
     Log("ime_heightchanged: " & LastException)
End Try


And this is why we blame @Roycefer and a good reason for you to check these projects out.

jNativeHook
https://www.b4x.com/android/forum/t...tercepting-system-input-events.55826/#content
That wrapped this
https://github.com/kwhat/jnativehook/releases

jAWTRobot
https://www.b4x.com/android/forum/t...-keyboard-and-mouse-events-etc.55832/#content
that wrapped the Oracle's java.awt.Robot package.

Have fun and remember. To stop the nativehook it is left windows key + ESC. In playing with this I rebooted my machine a few times. :eek:

I do wish Erel would give us hooks into the IDE.

Let me know if you find bugs. So... (c)The World. As always, source code included.
Extend, use and share back if you add some things.

Thanks.
 

Attachments

  • InLineAddLogs1.0.1.zip
    3 KB · Views: 376
  • libs.zip
    213.7 KB · Views: 393
Last edited:

Roycefer

Well-Known Member
Licensed User
Longtime User
Neat stuff.

Take a look at AWTRobot.JVMAddShutdownHook(). It adds a shutdown hook so that an event sub is run as the JVM shuts down. You can unregister your NativeHook inside that sub so you aren't left with any dangling NativeHooks. You should test it out, though. There are some situations where the event sub doesn't run (like when the JVM crashes or is shut down by a task manager). It's been a while since I've played with it.
 

ThRuST

Well-Known Member
Licensed User
Longtime User
I need a simple GUI version of this hotkey concept that only triggers when i.e Shift + CTRL is pressed simultaniously and outputs a "Hello world" in the log or something can someone please upload a real simple solution for this? I want to bind a hotkey to a project I'm working on with B4J and Scene builder, cheers.
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
Problem with that is that the GUI gains focus and I never did figure out away to find the previous running app to send the key-strokes back to. With that said though a GUI app could be created that writes out a MAP or INI file that the console app then reads.
 

ThRuST

Well-Known Member
Licensed User
Longtime User
Hopefully Erel can give some advice how to get around that. It would be awesome to have a hotkey library as a standard part of the B4J IDE Libraries collection.
If someone can come with advice how to progress in this field we will all be very happy. Dear Erel, please give us an official hotkey library and help us :)
 

ThRuST

Well-Known Member
Licensed User
Longtime User
Please everyone go to forum chitchat and vote for if you prefer the Internal designer or Scene builder. You find the voting poll under the "Letter to Gluon" post.
You can vote until december 2017 :)
 

ThRuST

Well-Known Member
Licensed User
Longtime User
JakeBullet70 I've been thinking of a solution for this hotkey quiz. What if it's possible to merge a non-GUI application into a GUI application, that might make it work?
 

JakeBullet70

Well-Known Member
Licensed User
Longtime User
What if it's possible to merge a non-GUI application into a GUI application

I do not believe that is possible. But as I posted before. You can create a separate GUI that writes out the data and have the non GUI app read it. That will work.
 

ThRuST

Well-Known Member
Licensed User
Longtime User
Another way, how about using calls to JavaObjects from a native Java solution?
 

ThRuST

Well-Known Member
Licensed User
Longtime User
Neither am I, in fact I try to stay away from native Java. Ever since I discovered B4J I like JavaFX very much, but only because of Erels masterful work.
I very much a hotkey library to be standard in the libraries folder. B4J is awesome but lacks extended functionality that we all depend on will be created by Erel or experts in this community. Untill I learn more I will have to depend on that people help eachother, so B4J can expand because it has huge advantages vs native Java.
 
Top