Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在eclipse中使用JIntellitype_Java_Java Native Interface_Hotkeys_Registerhotkey - Fatal编程技术网

Java 在eclipse中使用JIntellitype

Java 在eclipse中使用JIntellitype,java,java-native-interface,hotkeys,registerhotkey,Java,Java Native Interface,Hotkeys,Registerhotkey,我正在尝试为我的java应用程序使用全局热键。我搜索了很多,最后决定使用JIntellitype。我了解到它使用JNI与操作系统交互。我从 我已经在我的项目中包含了jar,它显示在(project_name)->(Referenced libraries)->jintellitype_1.3.9.jar中。我是否正确导入了它 我编写了以下示例程序来测试它 import com.melloware.jintellitype.HotkeyListener; import com.melloware.

我正在尝试为我的java应用程序使用全局热键。我搜索了很多,最后决定使用JIntellitype。我了解到它使用JNI与操作系统交互。我从

我已经在我的项目中包含了jar,它显示在(project_name)->(Referenced libraries)->jintellitype_1.3.9.jar中。我是否正确导入了它

我编写了以下示例程序来测试它

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


public class Example1 {


    public static void main() throws Exception
    {
        System.out.println("Line 1");
    //JIntellitype.getInstance().registerHotKey(1, JIntellitype.MOD_WIN, (int)'A');
    //JIntellitype.getInstance().registerHotKey(2, JIntellitype.MOD_ALT + JIntellitype.MOD_SHIFT, (int)'B');

    hkey h=new hkey();
    h.init_hotkey();
    Thread.sleep(100);
    }
}

class hkey
{
    void init_hotkey()
    {
        System.out.println("line 2");
        JIntellitype.getInstance();
        JIntellitype.getInstance().registerHotKey(1, JIntellitype.MOD_WIN, (int)'A');
        JIntellitype.getInstance().addHotKeyListener(new HotkeyListener() {

            @Override
            public void onHotKey(int arg0) {
                // TODO Auto-generated method stub
                if (arg0 == 1)
                    System.out.println("WINDOWS+A hotkey pressed");

            }
        });


    }
}
它没有显示任何错误或警告。但是“行1”和“行2”没有打印。我的控制台在运行后会显示这一点

JIntellitype version "1.3.9"

Running on java version "1.7.0_55" (build 1.7.0_55-b13) from Oracle Corporation
Operating environment "Windows 7" version 6.1 on x86
For more information on JIntellitype please visit http://www.melloware.com
这是代码有问题还是我没有正确导入?
是否有JIntellitype的示例程序。这里有一个,但其中没有.java文件。它编译了.class文件

我已经解决了我的问题。我必须将DLL文件添加到项目中

(项目名称)->引用库->jintellitype-1.3.9->属性->本机库 ->给出dll文件所在的路径

这里可以看到jintellitype的一个示例

/*
*JIntellitype-----------版权所有2005-2006 Emil A.Lefkof III
* 
*我总是尽我最大的努力使一个程序变得有用和可靠,但请记住
*对于使用本程序,绝对没有任何保修条款
*下列用语:
* 
*根据Apache许可证2.0版(以下简称“许可证”)获得许可;你不可以
*除非符合许可证,否则请使用此文件。您可以获得一份
*许可证在
* 
* http://www.apache.org/licenses/LICENSE-2.0
* 
*除非适用法律要求或书面同意,软件
*根据许可证进行的分发是按“原样”分发的,没有
*明示或暗示的任何种类的保证或条件。见
*管理下权限和限制的特定语言的许可证
*执照。
*/
包装com.melloware;
导入java.awt.BorderLayout;
导入java.awt.Event;
导入java.awt.Frame;
导入java.awt.GraphicsEnvironment;
导入java.awt.Point;
导入java.awt.Rectangle;
导入java.awt.event.ActionEvent;
导入java.awt.event.ActionListener;
导入java.io.File;
导入javax.swing.JButton;
导入javax.swing.JFrame;
导入javax.swing.JPanel;
导入javax.swing.JScrollPane;
导入javax.swing.JTextArea;
导入javax.swing.border.EtchedBorder;
导入com.melloware.jintellitype.HotkeyListener;
导入com.melloware.jintellitype.IntellitypeListener;
导入com.melloware.jintellitype.jintellitype;
/**
*基于Swing的测试应用程序,用于测试JIntellitype库的所有功能。
*
*版权所有(c)2006 Melloware,Inc。
*@作者埃米尔·莱夫科夫三世
*@version 1.0
*/
公共类JIntellitypeTester扩展了JFrame,实现了HotkeyListener、IntellitypeListener{
专用静态JIntellitypeTester主机;
专用静态最终int窗口_A=88;
专用静态最终int ALT_SHIFT_B=89;
专用静态最终整数CTRL\u SHIFT\u C=90;
专用静态最终整型打印屏幕=91;
专用静态最终int F11=92;
专用静态最终int F12=93;
私有静态最终整数分号=94;
专用静态最终整数刻度=95;
私有最终JButton btnRegisterHotKey=new JButton();
私有最终JButton btnunlisterhotkey=new JButton();
私有最终JPanel bottomPanel=新JPanel();
私有最终JPanel主面板=新JPanel();
private final JPanel topPanel=新JPanel();
私有最终JScrollPane scrollPane=新JScrollPane();
私有最终JTextArea textArea=新JTextArea();
/**
*创建新表单。
*/
公共JIntellitypeTester(){
初始化组件();
}
/**
*启动此应用程序的主要方法。
*
*@param args任何命令行参数
*/
公共静态void main(字符串[]args){
System.out.println(新文件(“.”.getAbsolutePath());
//首先检查此应用程序的实例是否已经存在
//运行时,使用此JFrame的窗口标题的名称进行检查
if(JIntellitype.checkInstanceAlreadyRunning(“JIntellitype测试应用程序”)){
系统出口(1);
}
//下一步检查以确保可以找到JintellitypeDLL,并且我们正在运行
//Windows操作系统
如果(!JIntellitype.isJIntellitypeSupported()){
系统出口(1);
}
mainFrame=新的JIntellitypeTester();
mainFrame.setTitle(“JIntellitype测试应用程序”);
中心(主机);
mainFrame.setVisible(true);
mainFrame.initJIntellitype();
}
/*
*(非Javadoc)
*@see com.melloware.jintellitype.HotkeyListener#onHotKey(int)
*/
公用void on热键(int助手){
输出(“接收到WM_热键消息”+整数.toString(助手));
}
/*
*(非Javadoc)
*@see com.melloware.jintellitype.IntellitypeListener#onIntellitype(int)
*/
INTELLITYPE上的公共无效(int ACOMAND){
开关(A命令){
case JIntellitype.APPCOMMAND\u浏览器\u向后:
输出(“接收到浏览器\返回消息”+整数.toString(aCommand));
打破
case JIntellitype.APPCOMMAND\u浏览器\u收藏夹:
输出(“收到浏览器的收藏夹消息”+整数.toString(aCommand));
打破
case JIntellitype.APPCOMMAND\u浏览器\u转发:
输出(“收到浏览器转发消息”+整数.toString(aCommand));
打破
case JIntellitype.APPCOMMAND\u浏览器\u主页:
输出(“收到浏览器的主页消息”+整数.toString(aCommand));
打破
case JIntellitype.APPCOMMAND_浏览器_刷新:
输出(“接收到浏览器\刷新消息”+整数.toString(aCommand));
打破
case JIntellitype.APPCOMMAND\u浏览器\u搜索:
输出(“收到浏览器搜索消息”+整数.toString(aCommand));
打破
case JIntellitype.APPCOMMAND\u BROWSER\u STOP:
输出(“收到浏览器停止消息”
/*
 * JIntellitype ----------------- Copyright 2005-2006 Emil A. Lefkof III
 * 
 * I always give it my best shot to make a program useful and solid, but remeber
 * that there is absolutely no warranty for using this program as stated in the
 * following terms:
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.melloware;

import java.awt.BorderLayout;
import java.awt.Event;
import java.awt.Frame;
import java.awt.GraphicsEnvironment;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.EtchedBorder;

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

/**
 * Swing based test application to test all the functions of the JIntellitype library.
 * <p>
 * Copyright (c) 2006 Melloware, Inc. <http://www.melloware.com>
 * @author Emil A. Lefkof III <elefkof@ksmpartners.com>
 * @version 1.0
 */
public class JIntellitypeTester extends JFrame implements HotkeyListener, IntellitypeListener {

   private static JIntellitypeTester mainFrame;
   private static final int WINDOWS_A = 88;
   private static final int ALT_SHIFT_B = 89;
   private static final int CTRL_SHIFT_C = 90;
   private static final int PRINT_SCREEN = 91;
   private static final int F11 = 92;
   private static final int F12 = 93;
   private static final int SEMICOLON = 94;
   private static final int TICK = 95;
   private final JButton btnRegisterHotKey = new JButton();
   private final JButton btnUnregisterHotKey = new JButton();
   private final JPanel bottomPanel = new JPanel();
   private final JPanel mainPanel = new JPanel();
   private final JPanel topPanel = new JPanel();
   private final JScrollPane scrollPane = new JScrollPane();
   private final JTextArea textArea = new JTextArea();

   /**
    * Creates new form.
    */
   public JIntellitypeTester() {
      initComponents();
   }

   /**
    * Main method to launch this application.
    * <p>
    * @param args any command line arguments
    */
   public static void main(String[] args) {
      System.out.println(new File(".").getAbsolutePath());
      // first check to see if an instance of this application is already
      // running, use the name of the window title of this JFrame for checking
      if (JIntellitype.checkInstanceAlreadyRunning("JIntellitype Test Application")) {
         System.exit(1);
      }

      // next check to make sure JIntellitype DLL can be found and we are on
      // a Windows operating System
      if (!JIntellitype.isJIntellitypeSupported()) {
         System.exit(1);
      }

      mainFrame = new JIntellitypeTester();
      mainFrame.setTitle("JIntellitype Test Application");
      center(mainFrame);
      mainFrame.setVisible(true);
      mainFrame.initJIntellitype();
   }

   /*
    * (non-Javadoc)
    * @see com.melloware.jintellitype.HotkeyListener#onHotKey(int)
    */
   public void onHotKey(int aIdentifier) {
      output("WM_HOTKEY message received " + Integer.toString(aIdentifier));
   }

   /*
    * (non-Javadoc)
    * @see com.melloware.jintellitype.IntellitypeListener#onIntellitype(int)
    */
   public void onIntellitype(int aCommand) {

      switch (aCommand) {
      case JIntellitype.APPCOMMAND_BROWSER_BACKWARD:
         output("BROWSER_BACKWARD message received " + Integer.toString(aCommand));
         break;
      case JIntellitype.APPCOMMAND_BROWSER_FAVOURITES:
         output("BROWSER_FAVOURITES message received " + Integer.toString(aCommand));
         break;
      case JIntellitype.APPCOMMAND_BROWSER_FORWARD:
         output("BROWSER_FORWARD message received " + Integer.toString(aCommand));
         break;
      case JIntellitype.APPCOMMAND_BROWSER_HOME:
         output("BROWSER_HOME message received " + Integer.toString(aCommand));
         break;
      case JIntellitype.APPCOMMAND_BROWSER_REFRESH:
         output("BROWSER_REFRESH message received " + Integer.toString(aCommand));
         break;
      case JIntellitype.APPCOMMAND_BROWSER_SEARCH:
         output("BROWSER_SEARCH message received " + Integer.toString(aCommand));
         break;
      case JIntellitype.APPCOMMAND_BROWSER_STOP:
         output("BROWSER_STOP message received " + Integer.toString(aCommand));
         break;
      case JIntellitype.APPCOMMAND_LAUNCH_APP1:
         output("LAUNCH_APP1 message received " + Integer.toString(aCommand));
         break;
      case JIntellitype.APPCOMMAND_LAUNCH_APP2:
         output("LAUNCH_APP2 message received " + Integer.toString(aCommand));
         break;
      case JIntellitype.APPCOMMAND_LAUNCH_MAIL:
         output("LAUNCH_MAIL message received " + Integer.toString(aCommand));
         break;
      case JIntellitype.APPCOMMAND_MEDIA_NEXTTRACK:
         output("MEDIA_NEXTTRACK message received " + Integer.toString(aCommand));
         break;
      case JIntellitype.APPCOMMAND_MEDIA_PLAY_PAUSE:
         output("MEDIA_PLAY_PAUSE message received " + Integer.toString(aCommand));
         break;
      case JIntellitype.APPCOMMAND_MEDIA_PREVIOUSTRACK:
         output("MEDIA_PREVIOUSTRACK message received " + Integer.toString(aCommand));
         break;
      case JIntellitype.APPCOMMAND_MEDIA_STOP:
         output("MEDIA_STOP message received " + Integer.toString(aCommand));
         break;
      case JIntellitype.APPCOMMAND_VOLUME_DOWN:
         output("VOLUME_DOWN message received " + Integer.toString(aCommand));
         break;
      case JIntellitype.APPCOMMAND_VOLUME_UP:
         output("VOLUME_UP message received " + Integer.toString(aCommand));
         break;
      case JIntellitype.APPCOMMAND_VOLUME_MUTE:
         output("VOLUME_MUTE message received " + Integer.toString(aCommand));
         break;
      default:
         output("Undefined INTELLITYPE message caught " + Integer.toString(aCommand));
         break;
      }
   }

   /**
    * Centers window on desktop.
    * <p>
    * @param aFrame the Frame to center
    */
   private static void center(JFrame aFrame) {
      final GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
      final Point centerPoint = ge.getCenterPoint();
      final Rectangle bounds = ge.getMaximumWindowBounds();
      final int w = Math.min(aFrame.getWidth(), bounds.width);
      final int h = Math.min(aFrame.getHeight(), bounds.height);
      final int x = centerPoint.x - (w / 2);
      final int y = centerPoint.y - (h / 2);
      aFrame.setBounds(x, y, w, h);
      if ((w == bounds.width) && (h == bounds.height)) {
         aFrame.setExtendedState(Frame.MAXIMIZED_BOTH);
      }
      aFrame.validate();
   }

   /**
    * Method to register a hotkey using the RegisterHotKey Windows API call.
    * <p>
    * @param aEvent the ActionEvent fired.
    */
   private void btnRegisterHotKey_actionPerformed(ActionEvent aEvent) {
      // assign the WINDOWS+A key to the unique id 88 for identification
      JIntellitype.getInstance().registerHotKey(WINDOWS_A, JIntellitype.MOD_WIN, 'A');
      JIntellitype.getInstance().registerHotKey(ALT_SHIFT_B, JIntellitype.MOD_ALT + JIntellitype.MOD_SHIFT, 'B');
      JIntellitype.getInstance().registerSwingHotKey(CTRL_SHIFT_C, Event.CTRL_MASK + Event.SHIFT_MASK, 'C');

      // use a 0 for the modifier if you just want a single keystroke to be a
      // hotkey
      JIntellitype.getInstance().registerHotKey(PRINT_SCREEN, 0, 44);
      JIntellitype.getInstance().registerHotKey(F11, "F11");
      JIntellitype.getInstance().registerHotKey(F12, JIntellitype.MOD_ALT, 123);
      JIntellitype.getInstance().registerHotKey(SEMICOLON, 0, 186);
      JIntellitype.getInstance().registerHotKey(TICK, 0, 192);
      // clear the text area
      textArea.setText("");
      output("RegisterHotKey WINDOWS+A was assigned uniqueID 88");
      output("RegisterHotKey ALT+SHIFT+B was assigned uniqueID 89");
      output("RegisterHotKey CTRL+SHIFT+C was assigned uniqueID 90");
      output("RegisterHotKey PRINT_SCREEN was assigned uniqueID 91");
      output("RegisterHotKey F9 was assigned uniqueID 92");
      output("RegisterHotKey F12 was assigned uniqueID 93");
      output("RegisterHotKey SEMICOLON was assigned uniqueID 94");
      output("Press WINDOWS+A or ALT+SHIFT+B or CTRL+SHIFT+C in another application and you will see the debug output in the textarea.");
   }

   /**
    * Method to unregister a hotkey using the UnregisterHotKey Windows API call.
    * <p>
    * @param aEvent the ActionEvent fired.
    */
   private void btnUnregisterHotKey_actionPerformed(ActionEvent aEvent) {
      JIntellitype.getInstance().unregisterHotKey(WINDOWS_A);
      JIntellitype.getInstance().unregisterHotKey(ALT_SHIFT_B);
      JIntellitype.getInstance().unregisterHotKey(CTRL_SHIFT_C);
      JIntellitype.getInstance().unregisterHotKey(PRINT_SCREEN);
      JIntellitype.getInstance().unregisterHotKey(F11);
      JIntellitype.getInstance().unregisterHotKey(F12);
      JIntellitype.getInstance().unregisterHotKey(SEMICOLON);
      output("UnregisterHotKey WINDOWS+A");
      output("UnregisterHotKey ALT+SHIFT+B");
      output("UnregisterHotKey CTRL+SHIFT+C");
      output("UnregisterHotKey PRINT_SCREEN");
      output("UnregisterHotKey F9");
      output("UnregisterHotKey F12");
      output("UnregisterHotKey SEMICOLON");
      output("Press WINDOWS+A or ALT+SHIFT+B in another application and you will NOT see the debug output in the textarea.");
   }

   /**
    * This method is called from within the constructor to initialize the form.
    */
   private void initComponents() {
      mainPanel.setLayout(new BorderLayout());
      topPanel.setBorder(new EtchedBorder(1));
      bottomPanel.setLayout(new BorderLayout());
      bottomPanel.setBorder(new EtchedBorder(1));
      btnRegisterHotKey.setText("RegisterHotKey");
      btnRegisterHotKey.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            btnRegisterHotKey_actionPerformed(e);
         }
      });
      btnUnregisterHotKey.setText("UnregisterHotKey");
      btnUnregisterHotKey.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
            btnUnregisterHotKey_actionPerformed(e);
         }
      });
      topPanel.add(btnRegisterHotKey);
      topPanel.add(btnUnregisterHotKey);
      scrollPane.getViewport().add(textArea);
      bottomPanel.add(scrollPane, BorderLayout.CENTER);
      mainPanel.add(topPanel, BorderLayout.NORTH);
      mainPanel.add(bottomPanel, BorderLayout.CENTER);

      this.addWindowListener(new java.awt.event.WindowAdapter() {
         @Override
         public void windowClosing(java.awt.event.WindowEvent evt) {
            // don't forget to clean up any resources before close
            JIntellitype.getInstance().cleanUp();
            System.exit(0);
         }
      });

      this.getContentPane().add(mainPanel);
      this.pack();
      this.setSize(800, 600);
   }

   /**
    * Initialize the JInitellitype library making sure the DLL is located.
    */
   public void initJIntellitype() {
      try {

         // initialize JIntellitype with the frame so all windows commands can
         // be attached to this window
         JIntellitype.getInstance().addHotKeyListener(this);
         JIntellitype.getInstance().addIntellitypeListener(this);
         output("JIntellitype initialized");
      } catch (RuntimeException ex) {
         output("Either you are not on Windows, or there is a problem with the JIntellitype library!");
      }
   }

   /**
    * Send the output to the log and the text area.
    * <p>
    * @param text the text to output
    */
   private void output(String text) {
      textArea.append(text);
      textArea.append("\n");
   }

}