如何模拟多媒体键preSS(C语言)? [英] How to simulate multimedia key press (in C)?

查看:230
本文介绍了如何模拟多媒体键preSS(C语言)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现代的键盘有特殊的多媒体键,如暂停/播放或打开Web浏览器。是否可以编写一个程序,presses这些钥匙?

Modern keyboards have special multimedia keys, e.g. 'Pause/Play' or 'Open Web Browser'. Is it possible to write a program that "presses" these keys?

我想美元P c ^ $ PFER解决办法,但我会接受的语言无关的解决方案了。

I would prefer solution in C, but I would accept a language agnostic solution, too.

推荐答案

使用的SendInput的Windows API,如果你谈论的是在Win32下编程。

Use the SendInput Windows API, if you are talking about programming under Win32.

您需要建立输入结构,设置型部件INPUT_KEYBOARD。在文员(KEYBDINPUT型),可以设置VK(虚拟键)到您想要的VK code(例如,VK_MEDIA_NEXT_TRACK,VK_MEDIA_STOP)。

You need to build INPUT structures, setting the type member to INPUT_KEYBOARD. In the ki member (KEYBDINPUT type), you can set vk (virtual key) to your desired VK code (for example, VK_MEDIA_NEXT_TRACK, VK_MEDIA_STOP).

虚拟键codeS:<一href=\"http://msdn.microsoft.com/en-us/library/dd375731(v=VS.85).aspx\">http://msdn.microsoft.com/en-us/library/dd375731(v=VS.85).aspx

SendInput功能:<一href=\"http://msdn.microsoft.com/en-us/library/ms646310(v=VS.85).aspx\">http://msdn.microsoft.com/en-us/library/ms646310(v=VS.85).aspx

SendInput Function: http://msdn.microsoft.com/en-us/library/ms646310(v=VS.85).aspx

我没有测试以下,但应该是这样的:

I've not tested the following, but should be like this:

KEYBDINPUT kbi;
kbi.wVk = VK_MEDIA_STOP; // Provide your own
kbi.wScan = 0;
kbi.dwFlags = 0;  // See docs for flags (mm keys may need Extended key flag)
kbi.time = 0;
kbi.dwExtraInfo = (ULONG_PTR) GetMessageExtraInfo();

INPUT input;
input.type = INPUT_KEYBOARD;
input.ki   = kbi;

SendInput(1, &input, sizeof(INPUT));

这篇关于如何模拟多媒体键preSS(C语言)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆