怎么用黑魂mousefix.asigui

3596人阅读
Matlab GUI学习(15)
(1)打开GUIDE,添加一个坐标轴并保存
(2)添加鼠标响应事件:鼠标按下事件,鼠标运动事件,鼠标松开事件
(3)对相应事件编写程序
function varargout = guide_m(varargin)
% GUIDE_M MATLAB code for guide_m.fig
GUIDE_M, by itself, creates a new GUIDE_M or raises the existing
singleton*.
H = GUIDE_M returns the handle to a new GUIDE_M or the handle to
the existing singleton*.
GUIDE_M('CALLBACK',hObject,eventData,handles,...) calls the local
function named CALLBACK in GUIDE_M.M with the given input arguments.
GUIDE_M('Property','Value',...) creates a new GUIDE_M or raises the
existing singleton*.
Starting from the left, property value pairs are
applied to the GUI before guide_m_OpeningFcn gets called.
unrecognized property name or invalid value makes property application
All inputs are passed to guide_m_OpeningFcn via varargin.
*See GUI Options on GUIDE's Tools menu.
Choose &GUI allows only one
instance to run (singleton)&.
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help guide_m
% Last Modified by GUIDE v2.5 25-Aug-:37
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',
mfilename, ...
'gui_Singleton',
gui_Singleton, ...
'gui_OpeningFcn', @guide_m_OpeningFcn, ...
'gui_OutputFcn',
@guide_m_OutputFcn, ...
'gui_LayoutFcn',
'gui_Callback',
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
gui_mainfcn(gui_State, varargin{:});
% End initialization code - DO NOT EDIT
% --- Executes just before guide_m is made visible.
function guide_m_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
handle to figure
% eventdata
reserved - to be defined in a future version of MATLAB
structure with handles and user data (see GUIDATA)
% varargin
command line arguments to guide_m (see VARARGIN)
% Choose default command line output for guide_m
handles.output = hO
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%定义两个全局变量
global ButtonDown pos1;
ButtonDown =[];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes guide_m wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = guide_m_OutputFcn(hObject, eventdata, handles)
% varargout
cell array for returning output args (see VARARGOUT);
handle to figure
% eventdata
reserved - to be defined in a future version of MATLAB
structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.
% --- Executes on mouse press over figure background, over a disabled or
% --- inactive control, or over an axes background.
function figure1_WindowButtonDownFcn(hObject, eventdata, handles)
handle to figure1 (see GCBO)
% eventdata
reserved - to be defined in a future version of MATLAB
structure with handles and user data (see GUIDATA)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%鼠标按下事件响应
global ButtonDown pos1;
if(strcmp(get(gcf,'SelectionType'),'normal'))%判断鼠标按下的类型,mormal为左键
ButtonDown=1;
pos1=get(handles.axes1,'CurrentPoint');%获取坐标轴上鼠标的位置
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on mouse motion over figure - except title and menu.
function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
handle to figure1 (see GCBO)
% eventdata
reserved - to be defined in a future version of MATLAB
structure with handles and user data (see GUIDATA)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%鼠标运动事件的响应
global ButtonDown pos1;
if ButtonDown == 1
pos = get(handles.axes1, 'CurrentPoint');%获取当前位置
line([pos1(1, 1) pos(1, 1)], [pos1(1, 2) pos(1, 2)], 'LineWidth', 4);%划线
pos1 =%更新
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --- Executes on mouse press over figure background, over a disabled or
% --- inactive control, or over an axes background.
function figure1_WindowButtonUpFcn(hObject, eventdata, handles)
handle to figure1 (see GCBO)
% eventdata
reserved - to be defined in a future version of MATLAB
structure with handles and user data (see GUIDATA)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%鼠标按键抬起的响应事件
global ButtonD
ButtonDown = 0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
(4)运行测试(按下鼠标,移动鼠标划线)
(5)部分函数方法介绍
Matlab回调函数
SelectionType
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:119515次
积分:2200
积分:2200
排名:第16948名
原创:91篇
转载:15篇
评论:14条
(1)(7)(7)(12)(2)(7)(19)(51)【转】Matlab&GUI&鼠标事件
今天Google了一下Matlab是不是能跟踪鼠标移动的轨迹,真的可以!
Matlab GUI 如何响应鼠标事件
摘自:MATLAB 程式设计与应用
这些性质都是附属於一个图形视窗,因此,他们规范了在此图形视窗下,各项滑鼠事件的反应指令.
一般而言,我们希望滑鼠先被按下,然后再移动滑鼠时,才会触发移动时的反应指令.欲达到此效果,我们必须做下列项:
在滑鼠按钮被按下时,设定 WindowButtonMotionFcn 及 WindowButtonUpFcn 的值.
在滑鼠按钮被释放时,清除 WindowButtonMotionFcn 及 WindowButtonUpFcn 的值.
因此,只有在滑鼠按钮被按下,且滑鼠在移动时,对应於WindowButtonMotionFcn 的反应指令才会被呼叫.
以下我们用一个简单的例子来说明.在这个例子中,滑鼠事件会产生下列反应:
按下滑鼠时,MATLAB 指令视窗会出现「Mouse down!」的讯息.
按下并移动滑鼠时,MATLAB 会在图形视窗画出滑鼠轨迹,并指令视窗印出「Mouse is
moving!」及当时滑鼠的位置.
释放滑鼠时,MATLAB 指令视窗会出现「Mouse up!」的讯息.
function tmouse(action)
% TMOUSE 本例展示如何以Handle Graphics来设定滑鼠事件(Mouse
% Events)的反应指令(Callbacks)
if nargin == 0, action = 'start'; end
&switch(action)
&&% 开启图形视窗
&&case 'start',
&&&axis([0 1 0
1]);% 设定图轴范围
将图轴加上图框
&&&title('Click
and drag your mouse in this window!');
设定滑鼠按钮被按下时的反应指令为「tmouse down」
&&&set(gcf,
'WindowButtonDownFcn', 'tmouse down');
&&% 滑鼠按钮被按下时的反应指令
&&case 'down',
设定滑鼠移动时的反应指令为「tmouse move」
&&&set(gcf,
'WindowButtonMotionFcn', 'tmouse move');
设定滑鼠按钮被释放时的反应指令为「tmouse up」
&&&set(gcf,
'WindowButtonUpFcn', 'tmouse up');
&&&% 列印「Mouse
down!」讯息
&&&fprintf('Mouse
down!\n');
&&% 滑鼠移动时的反应指令
&&case 'move',
&&&currPt =
get(gca, 'CurrentPoint');
currPt(1,1);
currPt(1,2);
&&&line(x, y,
'marker', '.', 'EraseMode', 'xor');
&&&% 列印「Mouse is
moving!」讯息及滑鼠现在位置
&&&fprintf('Mouse
is moving! Current location = (%g, %g)\n', currPt(1,1),
currPt(1,2));
&&% 滑鼠按钮被释放时的反应指令
&&case 'up',
清除滑鼠移动时的反应指令
&&&set(gcf,
'WindowButtonMotionFcn', '');
清除滑鼠按钮被释放时的反应指令
&&&set(gcf,
'WindowButtonUpFcn', '');
&&&% 列印「Mouse
&&&fprintf('Mouse
已投稿到:
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。用pywin32实现windows模拟鼠标及键盘动作
字体:[ ] 类型:转载 时间:
这篇文章主要介绍了用pywin32实现windows模拟鼠标及键盘动作的示例,需要的朋友可以参考下
因为要批量用某软件处理一批eps文件,所以要模拟鼠标及键盘动作,使其能够自动化操作。
代码如下:#-*-coding:utf-8-*-import osimport timeimport win32guiimport win32apiimport win32confrom PIL import ImageGrab
#os.startfile("D:\\artcut6\\Prog\\Artcut6.exe")#time.sleep(1)
wdname1=u"文泰刻绘2009[] - [无标题-1]"w1hd=win32gui.FindWindow(0,wdname1)print w1hdw2hd=win32gui.FindWindowEx(w1hd,None,None,None)print w2hd
def aotohelper_wt(i):&#获取窗口焦点&win32gui.SetForegroundWindow(w2hd)&#快捷键Alt+F&win32api.keybd_event(18,0,0,0)&&&&& # Alt&win32api.keybd_event(70,0,0,0)&&&& # F&win32api.keybd_event(70,0,win32con.KEYEVENTF_KEYUP,0)& #释放按键&win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0)
&#快捷键I&win32api.keybd_event(73,0,0,0)&&&& # I&win32api.keybd_event(73,0,win32con.KEYEVENTF_KEYUP,0)
&time.sleep(0.2)&wdname3=u"打开"&w3hd=win32gui.FindWindow(None,wdname3)& #”打开“ 窗口句柄&& &#print w3hd
&#win32gui.MoveWindow(w3hd, 50, 50, 300, 200, True)&if i&=9:&&msg="YC-00"+str(i)&elif 10&=i&=99:&&msg="YC-0"+str(i)&else:&&msg="YC-"+str(i)&edithd=win32gui.FindWindowEx(w3hd,None,"Edit",None)&win32api.SendMessage(edithd,win32con.WM_SETTEXT,None,msg)&time.sleep(0.1)&#btnhd=win32gui.FindWindowEx(w3hd,None,"BUTTON",None)&#print btnhd&#模拟快捷键Alt+O&win32api.keybd_event(18,0,0,0)&&&&& # Alt&win32api.keybd_event(79,0,0,0)&&&& # O&win32api.keybd_event(79,0,win32con.KEYEVENTF_KEYUP,0)& #释放按键&win32api.keybd_event(18,0,win32con.KEYEVENTF_KEYUP,0)&time.sleep(0.1)&#模拟鼠标操作&win32api.SetCursorPos([30,150])&&& #为鼠标焦点设定一个位置&win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,0,0,0,0) &win32api.SetCursorPos([500,500])&win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,0,0,0,0)&time.sleep(0.1)&#模拟快捷键F7(极限观察)&win32api.keybd_event(118,0,0,0)&&&& # F7&win32api.keybd_event(118,0,win32con.KEYEVENTF_KEYUP,0)& #释放按键&time.sleep(0.2)&#利用PIL截屏&path="C:\\Users\\LY\\Desktop\\pic\\"&filename="YC-"+str(i)+".jpg"&im=ImageGrab.grab()&im.save(path+filename)
&#模拟快捷键F8(回到原页面大小)&win32api.keybd_event(119,0,0,0)&&&& # F8&win32api.keybd_event(119,0,win32con.KEYEVENTF_KEYUP,0)& #释放按键
&#模拟键盘事件delete&win32api.keybd_event(46,0,0,0)&&&& # Delete&win32api.keybd_event(46,0,win32con.KEYEVENTF_KEYUP,0)& #释放按键&time.sleep(1)
for i in range(2,85):&aotohelper_wt(i)&print iprint "work done!"
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具

我要回帖

更多关于 darksoulsmousefix 的文章

 

随机推荐