SendInput模拟键盘事件控制暴风影音的播放和停止

1

This function synthesizes keystrokes, stylus and mouse motions, and button clicks.

UINT SendInput(
  UINT nInputs, 
  LPINPUT pInputs, 
  int cbSize 
); 
Parameters
nInputs 
Specifies how many structures pInputs points to. 
pInputs 
Pointer to an array of INPUT structures. Each structure represents an event to be inserted into the keyboard or mouse input stream. 
cbSize 
Specifies the size of an INPUT structure. If cbSize is not the size of an INPUT structure, the function will fail. 
Return Values
The number of events that the function inserted into the keyboard or mouse input stream indicates success. To get extended error information, call GetLastError. 


2

This structure is used by the SendInput function to synthesize keystrokes, stylus and mouse motions, and button clicks.

typedef struct tagINPUT {
  DWORD type;
  union {
    MOUSEINPUT mi;
    KEYBDINPUT ki;
    HARDWAREINPUT hi; 
  };
} INPUT, *PINPUT, FAR* LPINPUT;
Members
type 
Indicates the type of device information this structure carries. It is one of the following values. Value Description 
INPUT_HARDWARE The hi union member is valid. 
INPUT_KEYBOARD The ki union member is valid. 
INPUT_MOUSE The mi union member is valid. 

mi 
MOUSEINPUT structure that contains information about simulated mouse input. 
ki 
KEYBDINPUT structure that contains information about simulated keyboard input. 
hi 
HARDWAREINPUT structure that contains information about a simulated input device message

实例:

3

HWND hWnd=::FindWindow(_T("Baofeng_StormPlayer"),NULL);
	if (hWnd!=NULL)
	{
		::ShowWindow(hWnd,SW_SHOWNORMAL);
		::SetForegroundWindow(hWnd);
		INPUT m_InPut[2]={0};
		//键盘消息,将type置为INPUT_KEYBOARD;如果是鼠标消息,需将type置为INPUT_MOUSE
		m_InPut[0].type=m_InPut[1].type/*=m_InPut[2].type=m_InPut[3].type=m_InPut[4].type=m_InPut[5].type*/=INPUT_KEYBOARD;
		//将type置为键盘消息后,其INPUT结构中的ki结构是可以使用的,hi、mi结构不可使用
		m_InPut[0].ki.wVk=VK_SPACE;//空格

		m_InPut[1].ki.wVk=VK_SPACE;
		m_InPut[1].ki.dwFlags=KEYEVENTF_KEYUP;
		SendInput(sizeof(m_InPut)/sizeof(m_InPut[0]),m_InPut,sizeof(INPUT));
	}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小米的修行之路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值