windows鼠标信息管理与键盘模拟函数,windows函数

1、鼠标坐标难点

 BOOL GetWindowRect(

   HWND hWnd,     LPRECT lpRect  );**

  RECT x;//定义多个二维数组x

  ::GetWindowRect(hwnd,&x);

 

  POINT P;//x,y  RECT型 X 的指针

  GetCursorPos(&p);          //取当前鼠标坐标指针

  SetCursorPos(x+r1.left,y+r1.top);  //设置下一步鼠标坐标指针

  SetCursorPos(p.x,p.y);        //还原鼠标坐标

 

2、模拟鼠标新闻

                LRESULT SendMessage(
  HWND hWnd**,
 
UINT Msg,
 
WPARAM wParam,
 
LPARAM lParam 【ca88亚洲城亚洲官网】windows鼠标消息处理与键盘模拟函数,它的WndProc就处理鼠标与键盘消息。);** 

int x=?,y=?;

                              //y<<16)+x=lParam

                              //lParam可由SPY++拦截获取,亦可总结

*                              //eg.x=655;y=577
lparam 0x0241028f*

*                              //      0x
0172 01f3*

*                              //  
y=370  x= 499*

左键单击模拟:

  SendMessage(hwnd,WM_LBUTTONDOWN,0,(y<<16)+x);

  SendMessage(hwnd,WM_LBUTTONUP,0,(y<<16)+x); 

 左键双击模拟:

*  SendMessage(hwnd,WM_LBUTTONDBLCLK,0,(y<<16)+x); *

 

右键单击模拟:

  SendMessage(hwnd,WM_RBUTTONDOWN,0,(y<<16)+x);

  SendMessage(hwnd,WM_RBUTTONUP,0,(y<<16)+x); 

右键双击模拟:

*  SendMessage(hwnd,WM_RBUTTONDBLCLK,0,(y<<16)+x); *

 

2、鼠标事件 

 

VOID mouse_event(
  DWORD dwFlags, 
  DWORD dx, 
  DWORD dy, 
  DWORD dwData, 
  DWORD dwExtraInfo
);

左键单击新闻:
  mouse_event(mouse_event_LEFTUP,0,0,0,0);         //第一个参数位
鼠标操作情状

  mouse_event(mouse_event_LEFTDOWN,0,0,0,0); 

左键双击音讯:

  mouse_event(mouse_event_LBUTTONDBLCLK,0,0,0,0); 

 

 

右键单击音讯
  mouse_event(MOUSEEVENTF_REFTUP,0,0,0,0); 

  mouse_event(MOUSEEVENTF_LEFTDOWN,0,0,0,0); 

 

 

右键双击音讯:
  mouse_event(mouse_event_RBUTTONDBLCLK,0,0,0,0); 

键盘模拟函数

  VOID keybd_event(      

    BYTE bVk,
    BYTE bScan,
    DWORD dwFlags,
    PTR dwExtraInfo
);

  调用:

  keybd_event(13, 0, 0 ,0);    //第后生可畏参数键值  13 回车

 

1、鼠标坐标难题 BOOL GetWindowRect( HWND hWnd , LPRECT lpRect ); RECT
x;//定义五个二维数组x ::GetWindo…

只顾,这一个函数唯有Private风流洒脱种方式(也正是不容许覆盖,但仍在动态表格中卡塔 尔(英语:State of Qatar)(非常注意,这里依然没有WM_PAINT函数)

因为要批量用某软件管理一群eps文件,所以要效仿鼠标及键盘动作,使其可以自动化操作。

  TControl = class(TComponent)
  private
    // 15个私有消息处理,大多是鼠标消息。注意,消息函数大多只是一个中介,且TWinControl并不重写。
    procedure WMNCLButtonDown(var Message: TWMNCLButtonDown); message WM_NCLBUTTONDOWN;
    procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;
    procedure WMRButtonDown(var Message: TWMRButtonDown); message WM_RBUTTONDOWN;
    procedure WMMButtonDown(var Message: TWMMButtonDown); message WM_MBUTTONDOWN;
    procedure WMLButtonDblClk(var Message: TWMLButtonDblClk); message WM_LBUTTONDBLCLK;
    procedure WMRButtonDblClk(var Message: TWMRButtonDblClk); message WM_RBUTTONDBLCLK;
    procedure WMMButtonDblClk(var Message: TWMMButtonDblClk); message WM_MBUTTONDBLCLK;
    procedure WMLButtonUp(var Message: TWMLButtonUp); message WM_LBUTTONUP;
    procedure WMRButtonUp(var Message: TWMRButtonUp); message WM_RBUTTONUP;
    procedure WMMButtonUp(var Message: TWMMButtonUp); message WM_MBUTTONUP;
    //
    procedure WMMouseMove(var Message: TWMMouseMove); message WM_MOUSEMOVE;
    procedure WMMouseWheel(var Message: TWMMouseWheel); message WM_MOUSEWHEEL;
    procedure WMCancelMode(var Message: TWMCancelMode); message WM_CANCELMODE;
    procedure WMWindowPosChanged(var Message: TWMWindowPosChanged); message WM_WINDOWPOSCHANGED; // 重新计算最大化最小化的限制和坞里的尺寸
    procedure WMContextMenu(var Message: TWMContextMenu); message WM_CONTEXTMENU; // 真正展开右键菜单,其子类虽然覆盖这个函数,但反而只是帮助发送而已(发送给图形控件,为其增加右键菜单功能)。
    // 17个组件事件(大多是简单函数,通知某件事情,一般没有实际内容)
    // CM_显示函数
    procedure CMVisibleChanged(var Message: TMessage); message CM_VISIBLECHANGED; // 显示属性被改变了,那么要调用InvalidateControl重画自己。fixme 不明白这句为什么一定要这样调用,而不是执行Invalidate函数
    procedure CMEnabledChanged(var Message: TMessage); message CM_ENABLEDCHANGED; // 3个函数都简单调用Invalidate; 但是注意,它有可能调用子类TWinControl的Invalidate函数
    procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
    procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
    procedure CMBiDiModeChanged(var Message: TMessage); message CM_BIDIMODECHANGED;
    procedure CMParentBiDiModeChanged(var Message: TMessage); message CM_PARENTBIDIMODECHANGED;
    // 颜色字体
    procedure CMParentFontChanged(var Message: TMessage); message CM_PARENTFONTCHANGED;
    procedure CMSysFontChanged(var Message: TMessage); message CM_SYSFONTCHANGED;  // 调用SetFont
    procedure CMParentColorChanged(var Message: TMessage); message CM_PARENTCOLORCHANGED;
    procedure CMParentShowHintChanged(var Message: TMessage); message CM_PARENTSHOWHINTCHANGED; // 调用 SetShowHint
    procedure CMHintShow(var Message: TMessage); message CM_HINTSHOW;
    procedure CMHitTest(var Message: TCMHitTest); message CM_HITTEST; // 测试鼠标消息对子控件是否起作用
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER; // important 有趣,给父控件发送CM_MOUSEENTER,为什么要依赖它来处理?
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
    procedure CMDesignHitTest(var Message: TCMDesignHitTest); message CM_DESIGNHITTEST; // important5 什么都不做,消息结果为未处理
    procedure CMFloat(var Message: TCMFloat); message CM_FLOAT;
    procedure CMMouseWheel(var Message: TCMMouseWheel); message CM_MOUSEWHEEL; // 给父控件发送CM_MOUSEWHEEL
end;

复制代码 代码如下:

再正是把它的WndProc列出来,那样它能管理的音讯就齐了:

#-*-coding:utf-8-*-
import os
import time
import win32gui
import win32api
import win32con
from PIL import ImageGrab

procedure TControl.WndProc(var Message: TMessage);
var
  Form: TCustomForm;
  KeyState: TKeyboardState;
  WheelMsg: TCMMouseWheel;
begin  
  if (csDesigning in ComponentState) then
  begin
    Form := GetParentForm(Self);
    if (Form <> nil) and (Form.Designer <> nil) and
      Form.Designer.IsDesignMsg(Self, Message) then Exit //消息由窗体来处理
  end;
  //窗体可以为其拥有的组件来处理键盘消息
  if (Message.Msg >= WM_KEYFIRST) and (Message.Msg <= WM_KEYLAST) then
  begin
    Form := GetParentForm(Self);
    if (Form <> nil) and Form.WantChildKey(Self, Message) then Exit;
  end
  // important 图形控件的鼠标处理都在这里
  else if (Message.Msg >= WM_MOUSEFIRST) and (Message.Msg <= WM_MOUSELAST) then
  begin
    //如果组件不可以接受和处理双击消息,就将双击消息映射为单击消息。
    if not (csDoubleClicks in ControlStyle) then
      case Message.Msg of
        WM_LBUTTONDBLCLK, WM_RBUTTONDBLCLK, WM_MBUTTONDBLCLK:
          Dec(Message.Msg, WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
      end;
    case Message.Msg of
      WM_MOUSEMOVE:
        Application.HintMouseMessage(Self, Message); // 如果是鼠标移动的消息,则出现hint窗口
      WM_LBUTTONDOWN, WM_LBUTTONDBLCLK: // 如果是左键被按下,或者双击,如果是自动拖动模式,则开始拖动,并将左键按下的状态加入组件的状态。
        begin
          if FDragMode = dmAutomatic then
          begin
            BeginAutoDrag;
            Exit;
          end;
          Include(FControlState, csLButtonDown); // important 为图形控件(也可为Win控件)增加鼠标点击状态。点击Button就会执行到这里来。
        end;
      WM_LBUTTONUP:
        Exclude(FControlState, csLButtonDown); //如果是左键放开,则将左键按下的状态剔除。
    else
      with Mouse do
        if WheelPresent and (RegWheelMessage <> 0) and //如果鼠标有滚轮,并且滚轮滑动时发出了消息
          (Message.Msg = RegWheelMessage) then
        begin
          GetKeyboardState(KeyState); // API,将256虚拟键的状态拷贝到缓存中去
          with WheelMsg do //填充记录
          begin
            Msg := Message.Msg;
            ShiftState := KeyboardStateToShiftState(KeyState);
            WheelDelta := Message.WParam;
            Pos := TSmallPoint(Message.LParam);
          end;
          MouseWheelHandler(TMessage(WheelMsg)); // 类函数,派发鼠标滚轮的消息
          Exit;
        end;
    end;
  end
  else if Message.Msg = CM_VISIBLECHANGED then
    with Message do
      SendDockNotification(Msg, WParam, LParam);
  Dispatch(Message); // 到了这里,已经无法再使用WndProc方法向父类传递消息了,所以使用Dispatch。而且必定向上传递(一般情况下TControl的父类不会不响应这些消息)
end;

#os.startfile(“D:\\artcut6\\Prog\\Artcut6.exe”)
#time.sleep(1)

 当然还也会有DefaultHandler:

wdname1=u”文泰刻绘二〇〇九[] – [无标题-1]”
w1hd=win32gui.FindWindow(0,wdname1)
print w1hd
w2hd=win32gui.FindWindowEx(w1hd,None,None,None)
print w2hd

相关文章