简体   繁体   English

使用C ++使用虚拟键拍摄屏幕截图

[英]Take screenshot using virtual keys using c++

I want to make a program which takes screenshot whenever it runs. 我想制作一个在运行时需要截图的程序。 For that, I thought of using virtual keys but i am not able to press two keys simultaneously. 为此,我想到了使用虚拟键,但无法同时按下两个键。 I am trying to do this in Microsoft windows 8.1 and trying to press 我正在尝试在Microsoft Windows 8.1中执行此操作并尝试按 Windows键 + Print Scrn simultaneously. +同时打印Scrn

You can send multiple keys to the OS with keybd_event() . 您可以使用keybd_event()将多个密钥发送到操作系统。 The first time you call it you will send the windows key and tell it to stay down. 第一次调用它时,您将发送Windows键并告诉它保持按下状态。 Then you will do the same with the printscreen button. 然后,您将使用“打印屏幕”按钮执行相同的操作。 After you do that you need to call the function again to lift each key in reverse order. 完成此操作后,您需要再次调用该函数以相反的顺序抬起每个键。 You should be able to use: 您应该可以使用:

keybd_event(VK_LWIN, 0, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0);
keybd_event(VK_LWIN, 0, KEYEVENTF_KEYUP, 0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM