永发信息网

请教使用postmessage发送键盘消息时,参数如果设置

答案:2  悬赏:20  手机版
解决时间 2021-01-30 05:52
请教使用postmessage发送键盘消息时,参数如果设置
最佳答案
DllImport("user32.dll")]
static extern bool PostMessage(int hwnd, int msg, uint wParam, uint lParam);
参数说明:int hwnd, int msg, uint wParam, uint lParam
第一参数是记事本的窗口句柄,这点必须要确认
第二个参数是消息windows消息,用WM_CHAR试试,在C#中需要定义WM_CHAR或者直接填WM_CHAR的值0x0102
第三个参数填H的键码
第四个参数是特征码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
namespace TankLibrary
{
public class Win32API
{
[DllImport("user32.dll", EntryPoint = "FindWindow", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr hwnd);

[DllImport("Gdi32.dll")]
public static extern uint GetPixel(IntPtr hdc, int nXPos, int nYPos);

[DllImport("user32.dll")]
public static extern int mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo);
const int MOUSEEVENTF_MOVE = 0x0001; //移动鼠标
public const int MOUSEEVENTF_LEFTDOWN = 0x0002; //模拟鼠标左键按下
public const int MOUSEEVENTF_LEFTUP = 0x0004; //模拟鼠标左键抬起
const int MOUSEEVENTF_RIGHTDOWN = 0x0008; //模拟鼠标右键按下
const int MOUSEEVENTF_RIGHTUP = 0x0010; //模拟鼠标右键抬起
const int MOUSEEVENTF_MIDDLEDOWN = 0x0020; //模拟鼠标中键按下
const int MOUSEEVENTF_MIDDLEUP = 0x0040; //模拟鼠标中键抬起
const int MOUSEEVENTF_ABSOLUTE = 0x8000; //标示是否采用绝对坐标

public const int HWND_TOPMOST = -1;
public const int SWP_SHOWWINDOW = 40;

[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}

[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern int SetWindowPos(int hWnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
[DllImport("user32.dll")]
public static extern IntPtr GetWindowRect(IntPtr hWnd, ref RECT rect);
[DllImport("user32.dll")]
public static extern IntPtr GetWindowRect(IntPtr hWnd, ref Rectangle rect);

[DllImport("user32.dll")]
public static extern Int32 ReleaseDC(IntPtr hwnd, IntPtr hdc);
[DllImport("user32", CharSet = CharSet.Ansi, SetLastError = true, ExactSpelling = true)]
public static extern bool SetForegroundWindow(IntPtr hwnd);
[DllImport("user32.dll", EntryPoint = "PostMessage")]
public static extern IntPtr PostMessage1(IntPtr hWnd, uint Msg, int wParam, int lParam);
[DllImport("user32.dll")]
public static extern bool SetCursorPos(int x, int y);

public static void ClickOn(IntPtr hwnd, int x, int y)
{
uint WM_LBUTTONDOWN = 0x0201;
uint WM_LBUTTONUP = 0x0202;
PostMessage1(hwnd, WM_LBUTTONDOWN, x, y);
PostMessage1(hwnd, WM_LBUTTONUP, x, y);
}
}

}
全部回答

如果发送的是键盘消息(类似与按键盘) 就可以截取,否则 是截取不到的。

我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
康家政保洁家电清洁地址好找么,我有些事要过
现在学3D。游戏制作.电影特效制作等找工作容
第一题.﹙20a的立方-5a的平方b的平方×3a的平
吃吃的爱什么时候上映?吃吃的爱发布会小S林
龙辉布行地址有知道的么?有点事想过去
渐入家境保洁地址在什么地方,想过去办事
父母下堂是什么意思
出牌的意思是什么啊?知道的请说下!
How different life today is from what was
如何有效开展初中语文阅读教学
高二美术生需要买一个ipad.用于学习,请问买
顾家家政保洁地址好找么,我有些事要过去
在手机上怎么进行电影票预订
雅星家纺地址有知道的么?有点事想过去
屯沴的意思是什么啊?知道的请说下!
推荐资讯
各位高人们我想买一台吉利全球鹰的GX7尊贵版
牛矢的意思是什么啊?知道的请说下!
永安旅馆(长治郊区)地址有知道的么?有点事想
广州市花都一中好还是广州市白云艺术中学好
对老师的新年成语怎么说
mac怎么用终端打开mysql
下列属于商品的是 A爸爸送你的生
【致橡树英文版】能不能把致橡树英文版告诉我
时空隧道VR轰趴馆地址有知道的么?有点事想过
地球上A,B两点都在北纬45度圈上,A,B的球面距
美妮秀专业减肥美容地址有知道的么?有点事想
巴黎美术学院学费多少
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?