2

how to get Scan code/physical key. I have the virtual key code/hexadecimal but i don't know the function or method to get the Scan Code. I have searched but found none so, can someone help me. This is my Code:

import java.awt.event.*;
import javax.swing.*;
import java.util.*;

public class lab1 extends JFrame {
    lab1(){
        addKeyListener(new KeyAdapter(){
            @Override
            public void keyPressed(KeyEvent e){
                int keyCode = e.getKeyCode();
                char keyChar = e.getKeyChar();
                System.out.println("The key character is: ");
                System.out.println(keyChar);
                System.out.println("The ASCII code is:");
                System.out.println(keyCode);
                if(KeyCode == KeyEvent.VK_A){
                   int a =0x0041; 
                }
            }
        });
    }

    public static void main(String[] args){
       SwingUtilities.invokeLater(() -> {
           lab1 l = new lab1();

           l.setFocusable(true);
           l.setVisible(true);

       });  
    }
}

That is it, i have searched and searched but found none, please your help will be appreciated.

umeh oscar
  • 139
  • 9
  • 2
    A virtual key code does not directly map to a physical key, so it's difficult to understand what you mean. Could you rephrase / add a little more info please? – Tibrogargan Oct 24 '16 at 04:01
  • Yes, i know it doesn't directly map to a physical key. I want to know if there is a method in java library that can do something like this: i.e int scan = MapVirtualKey((int)e.KeyValue, 0); string scanCode = Convert.ToString(scan, 16); p.s: this is C# – umeh oscar Oct 24 '16 at 10:36
  • 1
    [This](http://stackoverflow.com/questions/17255549/how-can-i-get-the-keyboard-scan-code-in-java) might help – Tibrogargan Oct 24 '16 at 16:46

0 Answers0