在我们编写远程控制软件的时候,我们会发现要想解锁server端我们就得发送这三个键的虚拟。
下面我说一下解决过程
1.一开始,决定通过keybd_event()来模拟键盘
keybd_event(vk_control,mapvirtualkey(vk_control,0),0,0);
keybd_event(vk_menu,mapvirtualkey(vk_menu,0),0,0);
keybd_event(vk_delete,mapvirtualkey(vk_delete,0),0,0);
keybd_event(vk_delete,mapvirtualkey(vk_delete,0),keyeventf_keyup,0);
keybd_event(vk_menu,mapvirtualkey(vk_menu,0),keyeventf_keyup,0);
keybd_event(vk_control,mapvirtualkey(vk_control,0),keyeventf_keyup,0);
发现只能模拟ctrl+alt两个键的效果,然而其他的两个键的都可以模拟比如win+d。不知道是不是keybd_event()只能模拟两键还是因为
ctrl+alt+delete的特殊性,望高手告之,在此谢过。
2.运用postmessage(hwnd_broadcast, wm_hotkey, 0, makelong(mod_alt | mod_control, vk_delete));来发送虚拟键盘,但是在winnt以后的系统里我们还有很多事情要做,比如:opendesktop()、openinputdesktop()、getthreaddesktop()、setthreaddesktop()、closedesktop()、getuserobjectinformation()
代码如下:
#include "windows.h"
bool simulatealtcontroldel();
void main()
{
simulatealtcontroldel();
}
bool simulatealtcontroldel()
{
hdesk hdeskcurrent;
hdesk hdesk;
hwinsta hwinstacurrent;
hwinsta hwinsta;
//
// save the current window station
//
hwinstacurrent = getprocesswindowstation();
if (hwinstacurrent == null)
return false;
//
// save the current desktop
//
hdeskcurrent = getthreaddesktop(getcurrentthreadid());
if (hdeskcurrent == null)
return false;
//
// obtain a handle to winsta0 - service must be running
// in the localsystem account
//
hwinsta = openwindowstation("winsta0", false,
winsta_accessclipboard |
winsta_accessglobalatoms |
winsta_createdesktop |
winsta_enumdesktops |
winsta_enumerate |
winsta_exitwindows |
winsta_readattributes |
winsta_readscreen |
winsta_writeattributes);
if (hwinsta == null)
return false;
//
// set the windowstation to be winsta0
//
if (!setprocesswindowstation(hwinsta))
return false;
//
// get the default desktop on winsta0
//
hdesk = opendesktop("winlogon", 0, false,