0

I am developing a java swing application that performs different actions when buttons are pressed. For each of the buttons in the application I have configured and unique global hotkey (System Level) for example ALT+C stands for "Clear" This will clear the text entered in a textbox. Later I have exported my code as an executable file with all dependent jars. The Hotkeys declared works fine when running the application on my device. But, when I tried to run the same application on my friend's laptop hotkeys are not working.

import com.melloware.jintellitype.HotkeyListener;
import com.melloware.jintellitype.JIntellitype;

import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.Dimension;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.*;
import java.io.*;
import java.security.PublicKey;
import java.util.*;
import java.util.List;
import java.util.logging.Handler;

public class test_demo implements ActionListener {
    JTextField text_box;
    JButton Clear_btn;
    public static final int Clearbox = 1;
    public test_demo(){
        JFrame.setDefaultLookAndFeelDecorated(true);
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setTitle("TEST");
        frame.setLayout(new GridLayout(2, 1));
        text_box = new JTextField();
        text_box.setFont(new Font("Serif", Font.PLAIN, 20));
        frame.add(text_box);
        Clear_btn = new JButton("Clear");
        Clear_btn.setFont(new Font("Serif", Font.PLAIN, 20));
        Clear_btn.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Clear_box();
            }
        });
        frame.add(Clear_btn);
        int frameWidth = 400;
        int frameHeight = 250;
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        frame.setBounds((int) screenSize.getWidth() - frameWidth, 0, frameWidth, frameHeight);
        frame.setVisible(true);
        JIntellitype.getInstance().registerHotKey(Clearbox, JIntellitype.MOD_ALT, (int) 'C');
        JIntellitype.getInstance().addHotKeyListener(new HotkeyListener() {
            @Override
            public void onHotKey(int markcode) {
                switch (markcode){
                    case Clearbox:
                        Clear_box();
                        break;
                }
           }
        });
    }
    public static void main(String args[]){
        new test_demo();
    }
    public void Clear_box(){
        text_box.setText(null);
    }
    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==Clear_btn) {
            Clear_box();
        }}
}
  • What operating system is running on your friend's laptop? – Gilbert Le Blanc Dec 28 '21 at 09:34
  • If you are referring to this [JIntellitype](https://github.com/melloware/jintellitype) the that Web page states that _This library ONLY works on Windows._ So is your friend's laptop running Windows? By the way, is there a reason why you aren't using [key bindings](https://docs.oracle.com/javase/tutorial/uiswing/misc/keybinding.html)? – Abra Dec 28 '21 at 10:55
  • Yes we both are using windows 10 OS – sreekar reddy Dec 28 '21 at 11:34
  • I am Not using Key Bindings because it requires the application to be in focus, I want to trigger Button actions even when this application is minimised or while running in background – sreekar reddy Dec 28 '21 at 11:36

0 Answers0