首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >altgr不能与jnativehook一起工作?

altgr不能与jnativehook一起工作?
EN

Stack Overflow用户
提问于 2016-12-23 05:30:41
回答 1查看 145关注 0票数 0

这只是为了测试目的。

我试着修改了代码的某些部分,同时也阅读了api-docs。在begin中,我添加了"typedC += e.getKeyChar();“,它看起来像是记录altgr-键,但后来就不再是了。

如何改变它让工作altgr-键?

谢谢

代码语言:javascript
复制
   import java.io.BufferedWriter;
   import java.io.File;
   import java.io.FileNotFoundException;
   import java.io.FileWriter;
   import java.io.IOException;
   import java.util.logging.Level;
   import java.util.logging.LogManager;
   import java.util.logging.Logger;
   import javax.swing.JFileChooser;
   import org.jnativehook.GlobalScreen;
   import org.jnativehook.NativeHookException;
   import org.jnativehook.keyboard.NativeKeyEvent;
   import org.jnativehook.keyboard.NativeKeyListener;

   public class JkL implements NativeKeyListener {
    private String typedC = "";
    private String typedC1 = "";
    private final JFileChooser fc = new JFileChooser();
    private File direc;

    private void openFchooser1() throws FileNotFoundException,   
    InterruptedException, IOException, Exception {
     Thread.sleep(2000);
     int returnVal = fc.showDialog(null, "Choose a Logfile");
     if(returnVal == JFileChooser.APPROVE_OPTION) {
      direc = fc.getSelectedFile();
    }
 /* Construct the example object and initialze native hook. */
    GlobalScreen.addNativeKeyListener(new Kl());
    try {
        /* Register jNativeHook */
        GlobalScreen.registerNativeHook();
    } catch (NativeHookException ex) {
        /* Its error */
        System.err.println("There was a problem registering the native 
        hook.");
        System.err.println(ex.getMessage());
        System.exit(1);
    }

    // Clear previous logging configurations.
      LogManager.getLogManager().reset();

   // Get the logger for "org.jnativehook" and set the level to off. 
      Logger logger = 
      Logger.getLogger(GlobalScreen.class.getPackage().getName());
      logger.setLevel(Level.OFF);
 }

@Override
public void nativeKeyPressed(NativeKeyEvent nke) {
    throw new UnsupportedOperationException("Not supported yet."); //To 
   change body of generated methods, choose Tools | Templates.
}

@Override
public void nativeKeyReleased(NativeKeyEvent nke) {
    throw new UnsupportedOperationException("Not supported yet."); //To 
       change body of generated methods, choose Tools | Templates.
}

@Override
public void nativeKeyTyped(NativeKeyEvent nke) {
    throw new UnsupportedOperationException("Not supported yet."); //To  
        change body of generated methods, choose Tools | Templates.
}
 class Kl extends JkL {     
  /* Key Pressed */
  @Override
  public void nativeKeyPressed(NativeKeyEvent e) {
    //typedC += NativeKeyEvent.getKeyText(e.getKeyCode());
    typedC += e.getRawCode();
    typedC += e.getKeyChar();
    typedC += e.getKeyCode();
    try {
        writeToFile(typedC);
    } catch (IOException ex) {
        Logger.getLogger(JkL.class.getName()).log(Level.SEVERE, null, 
           ex);
    }
    /* Terminate program when one press ESCAPE */
    if (e.getKeyCode() == NativeKeyEvent.VC_F12) {
        try {
            GlobalScreen.unregisterNativeHook();
        } catch (NativeHookException ex) {
            Logger.getLogger(JkL.class.getName()).log(Level.SEVERE, 
            null, ex);
          }
         }
        }

  @Override 
  public void nativeKeyReleased(NativeKeyEvent e) {
    //System.out.println("Key Released: " +   
       //NativeKeyEvent.getKeyText(e.getKeyCode()));
  }

/* I can't find any output from this call */
@Override
public void nativeKeyTyped(NativeKeyEvent e) {
  //typedC1 += NativeKeyEvent.getKeyText(e.getKeyCode());
  typedC1 += e.getRawCode();
  typedC1 += e.getKeyChar();
  typedC1 += e.getKeyCode();
    try {
        writeToFile(typedC1);  
    } catch (IOException ex) {
        Logger.getLogger(JkL.class.getName()).log(Level.SEVERE, null, 
            ex); 
       }
      }
     }
    private void writeToFile(String ln) throws IOException {
     //System.out.println(direc);
     FileWriter fw = new FileWriter(direc); 
     try (BufferedWriter bw = new BufferedWriter(fw)) {
     bw.write(ln);
     bw.newLine();
     bw.flush();
    }
   } 
      public static void main(String[] args) throws 
          IOException,InterruptedException, Exception {  
      new JkL().openFchooser1();
     }   
    }
EN

回答 1

Stack Overflow用户

发布于 2017-01-16 01:41:54

什么操作系统?Linux上的2.0有一些已知的问题,但这些问题将在2.1中修复。如果有任何其他问题,您可能需要报告一个错误。请包括您的确切键盘布局,型号和语言。还提供了有关按下的键、观察到的行为和预期行为的详细信息。我只知道如何使用美国键盘,所以我不确定所有Alt-Gr语言/区域特定的键、口罩和锁是如何工作的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41291924

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档