B4J Library jAWTRobot - invoke keyboard and mouse events, etc...

Gandalf

Member
Licensed User
Longtime User
Hi,

I'm trying to do a screenshot with the code
B4X:
    rur.ScreenCurrentRectangleSetAsArbitrary(0, 0, rur.ScreenGetDimensions(0), rur.ScreenGetDimensions(1))
    rur.ScreenCaptureToFile("screenshot.png")
and the result has resolution of my screen set correctly to 1920x1080, but screenshot itself takes only part of the image (see below). This PC is laptop with only one screen. What I'm doing wrong?


UPDATE:
This is connected to Windows 10 scaling feature:

If I set it to 100%, screenshot takes all resulting image. But my vision is not so good to work with such scaling. Other third-party desktop capturing tools can work with any scaling somehow, producing screenshots with real resolution. Can it be done with this library also?
 
Last edited:

Cableguy

Expert
Licensed User
Longtime User
Wouldn't be easier to take a 100% screenshot, which works, and then resume the resulting image to 125%?
 

Gandalf

Member
Licensed User
Longtime User
Wouldn't be easier to take a 100% screenshot, which works, and then resume the resulting image to 125%?

I'm just curious if it is possible to get better resolution without scaling change. By the way, old screen capturing method which uses javaObject also suffers from scaling, but resulting image just has reduced resolution without black areas at right and bottom.
 

Roycefer

Well-Known Member
Licensed User
Longtime User
Have you tried using smaller or larger rectangles? If this app is only going to be for your own use, you can hard-code in your known scaling factor.
 

Gandalf

Member
Licensed User
Longtime User
Have you tried using smaller or larger rectangles? If this app is only going to be for your own use, you can hard-code in your known scaling factor.
Yes, I tried. The effect persists - at 125% scaling screenshot resolution is 1536x864 while screen is set to 1920x1080. Unfortunately this app is not for my use only, it is intended to be used in relatively critical process of customer's company.
 

Roycefer

Well-Known Member
Licensed User
Longtime User
How are your inline Java skills? Try this out:
B4X:
    /**
     * Assume 96 dpi is 100% screen scaling.
     * @return the system's screen resolution in dots/inch
     */
    public int ScreenGetResolutionInDpi()
    {
        return java.awt.Toolkit.getDefaultToolkit().getScreenResolution();
    }
Try this as a means of getting the scaling factor and then adjusting your rectangles accordingly. Let me know if it works. If so, I'll add it to the library.
 

Gandalf

Member
Licensed User
Longtime User
My inline Java skills are quite poor but enough to run this:
B4X:
Dim toolkit As JavaObject
toolkit.InitializeStatic("java.awt.Toolkit")
Dim res As Int = toolkit.RunMethodJO("getDefaultToolkit", Null).RunMethod("getScreenResolution", Null)
Log(res)
It returns 96 at 100% scaling and 120 at 125% scaling. But adjusting rectangle size to full resolution gives the same black area with smaller picture at top-left as in my first post here. The only thing I could do is to get rid of the black area using this method - and get the result like without using library.
 
Last edited:

Roycefer

Well-Known Member
Licensed User
Longtime User
Based on my preliminary search, it doesn't look like there's a standard API for battery level exposed in Java which means it won't be available with this library.

I've seen some solutions that use native access.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…