java获取系统鼠标位置(jni+dll应用)
来源:互联网 发布:汉诺塔小学生数学算法 编辑:程序博客网 时间:2024/04/30 10:55
最近玩游戏点击鼠标,按键觉得太辛苦了,想写辅助程序帮忙操作。java中没有找到获取系统鼠标的方法,就借助dll来实现。
先建立java文件MouseInfo.java
public class MouseInfo ...{
static...{
System.loadLibrary("MouseInfo");
}
public native static int getMousePosX();
public native static int getMousePosY();
public static void main(String[] args)throws Exception ...{
// TODO Auto-generated method stub
MouseInfo mouseInfo = new MouseInfo();
System.out.println("x:"+mouseInfo.getMousePosX()+"y:"+mouseInfo.getMousePosY());
}
}
static...{
System.loadLibrary("MouseInfo");
}
public native static int getMousePosX();
public native static int getMousePosY();
public static void main(String[] args)throws Exception ...{
// TODO Auto-generated method stub
MouseInfo mouseInfo = new MouseInfo();
System.out.println("x:"+mouseInfo.getMousePosX()+"y:"+mouseInfo.getMousePosY());
}
}
javac MouseInfo.java
javah MouseInfo
生成MouseInfo.h
/**//* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/**//* Header for class MouseInfo */
#ifndef _Included_MouseInfo
#define _Included_MouseInfo
#ifdef __cplusplus
extern "C" ...{
#endif
/**//*
* Class: MouseInfo
* Method: getMousePosX
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_MouseInfo_getMousePosX
(JNIEnv *, jclass);
/**//*
* Class: MouseInfo
* Method: getMousePosY
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_MouseInfo_getMousePosY
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif
#include <jni.h>
/**//* Header for class MouseInfo */
#ifndef _Included_MouseInfo
#define _Included_MouseInfo
#ifdef __cplusplus
extern "C" ...{
#endif
/**//*
* Class: MouseInfo
* Method: getMousePosX
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_MouseInfo_getMousePosX
(JNIEnv *, jclass);
/**//*
* Class: MouseInfo
* Method: getMousePosY
* Signature: ()I
*/
JNIEXPORT jint JNICALL Java_MouseInfo_getMousePosY
(JNIEnv *, jclass);
#ifdef __cplusplus
}
#endif
#endif
用vc建一个win32动态dll工程
建立StdAfx.h
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__9CE33D16_5EAB_479B_A1CE_AEC7E4B243B6__INCLUDED_)
#define AFX_STDAFX_H__9CE33D16_5EAB_479B_A1CE_AEC7E4B243B6__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxole.h> // MFC OLE classes
#include <afxodlgs.h> // MFC OLE dialog classes
#include <afxdisp.h> // MFC Automation classes
#endif // _AFX_NO_OLE_SUPPORT
#ifndef _AFX_NO_DB_SUPPORT
#include <afxdb.h> // MFC ODBC database classes
#endif // _AFX_NO_DB_SUPPORT
#ifndef _AFX_NO_DAO_SUPPORT
#include <afxdao.h> // MFC DAO database classes
#endif // _AFX_NO_DAO_SUPPORT
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__9CE33D16_5EAB_479B_A1CE_AEC7E4B243B6__INCLUDED_)
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__9CE33D16_5EAB_479B_A1CE_AEC7E4B243B6__INCLUDED_)
#define AFX_STDAFX_H__9CE33D16_5EAB_479B_A1CE_AEC7E4B243B6__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers
#include <afxwin.h> // MFC core and standard components
#include <afxext.h> // MFC extensions
#ifndef _AFX_NO_OLE_SUPPORT
#include <afxole.h> // MFC OLE classes
#include <afxodlgs.h> // MFC OLE dialog classes
#include <afxdisp.h> // MFC Automation classes
#endif // _AFX_NO_OLE_SUPPORT
#ifndef _AFX_NO_DB_SUPPORT
#include <afxdb.h> // MFC ODBC database classes
#endif // _AFX_NO_DB_SUPPORT
#ifndef _AFX_NO_DAO_SUPPORT
#include <afxdao.h> // MFC DAO database classes
#endif // _AFX_NO_DAO_SUPPORT
#include <afxdtctl.h> // MFC support for Internet Explorer 4 Common Controls
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC support for Windows Common Controls
#endif // _AFX_NO_AFXCMN_SUPPORT
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__9CE33D16_5EAB_479B_A1CE_AEC7E4B243B6__INCLUDED_)
建立MouseInfo.cpp
#include "MouseInfo.h"
#include "StdAfx.h"
JNIEXPORT jint JNICALL Java_MouseInfo_getMousePosX
(JNIEnv *, jclass)
...{
//获取当前系统鼠标的x坐标,返回int型
int xPos = 100;
POINT pt;
GetCursorPos(&pt);
xPos = pt.x;
return xPos;
}
JNIEXPORT jint JNICALL Java_MouseInfo_getMousePosY
(JNIEnv *, jclass)
...{
//获取当前系统鼠标的y坐标,返回int型
int yPos = 100;
POINT pt;
GetCursorPos(&pt);
yPos = pt.y;
return yPos;
}
#include "StdAfx.h"
JNIEXPORT jint JNICALL Java_MouseInfo_getMousePosX
(JNIEnv *, jclass)
...{
//获取当前系统鼠标的x坐标,返回int型
int xPos = 100;
POINT pt;
GetCursorPos(&pt);
xPos = pt.x;
return xPos;
}
JNIEXPORT jint JNICALL Java_MouseInfo_getMousePosY
(JNIEnv *, jclass)
...{
//获取当前系统鼠标的y坐标,返回int型
int yPos = 100;
POINT pt;
GetCursorPos(&pt);
yPos = pt.y;
return yPos;
}
将生成的MouseInfo.dll放入java项目中运行。
这样在java中就可以获取到鼠标的系统位置。
然后应用java中的Robot类来方便的处理各种模拟事件。也许这是一种多此一举的做法,因为习惯了java编程,所以这个思路就这么形成了。呵呵。
- java获取系统鼠标位置(jni+dll应用)
- (java)获取鼠标位置坐标
- Java中获取鼠标位置
- Qt获取鼠标位置(绝对位置、相对位置)
- 《JavaScript学习笔记》:获取鼠标的位置及应用
- 获取鼠标位置
- 如何获取鼠标位置
- Javascript获取鼠标位置
- 获取鼠标位置
- 获取鼠标点击位置
- 获取鼠标位置
- js获取鼠标位置
- js获取鼠标位置
- js获取鼠标位置
- 获取鼠标的位置
- jquery获取鼠标位置
- 获取鼠标移动位置
- jquery获取鼠标位置
- 五大法则构筑“人才金字塔”-微软中国研发集团的管理和文化
- Axis开发Web Service实例
- Trufun Kant 2007将同时集成eclipse3.2和vs.net2005
- .Net下几种日志管理方法
- 启发式搜索算法引论------A*算法理论与实践
- java获取系统鼠标位置(jni+dll应用)
- xie wen ben ri zhi
- 近期读书计划
- 最终决定转向C/C++了,准备在这里开博
- asp中通过vbs类实现rsa加密与解密
- 开博贺喜篇
- Delphi关于多线程同步的一些方法
- 如何学习加密与解密技术
- 开发式编程,声明式编程和产生式编程(www.mynetweaver.cn)