Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

keyboard - How to emulate fn button in Java Robot Class (possibly with jintellitype)

I am just trying to emulate a combination of fn key + space in a java program, as this would turn on the light on Lenovo ThinkPad, but I guess my question can be applied to several use-cases where fn+x is used on notebooks.

The thing is, as fn is no "standard key" of course Javas build in Robot Class has no key_event we could use, so I thought, ok let's get the int value for fn. I used "keyTweak" but it does not show the fn key and then I tried "KeyboardStateView" and this actually gave me the value of "255" when pressing fn. But perhaps you already anticipated what followed, for a quick test I wrote:

    public static void main(String[] args) {
            try {
               Robot robot = new Robot();
                robot.keyPress(255);
    
                robot.keyRelease(255);
    
            } catch (AWTException e) {
                System.err.println("Robot could not be created to emulate keyboard input: " + e.getCause());
            }
    
        }

All I get is:

Exception in thread "main" java.lang.IllegalArgumentException: Invalid key code

Any ideas on how to get a valid code for the fn key? Doing some searching some guys said there were able too, some said, they needed to use a lib like jintellitype because they found no valid scan code for the key.

But using it, I am also lost, I mean as far as I understand it, I can create hotkeys like this:

 JIntellitype.getInstance().registerHotKey(1, JIntellitype.MOD_WIN, (int)'A');

But I don't see a way how to do this for fn, I mean there is no Intellitype matching that k, I guess I would have to create one myself, but as I am just a beginner, this is way over my capability. Can someone give me a hint or point me to another perhaps easier solution?

Thank you all in advance for your time and patience! Chris

question from:https://stackoverflow.com/questions/65875459/how-to-emulate-fn-button-in-java-robot-class-possibly-with-jintellitype

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...