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();
}}
}