gpt4 book ai didi

c# - GetLastInputInfo 是用户特定的 - 是否有类似的东西可以提供机器范围的最后输入时间

转载 作者:行者123 更新时间:2023-11-30 17:24:18 27 4
gpt4 key购买 nike

根据 MSDN,http://msdn.microsoft.com/en-us/library/ms646302%28VS.85%29.aspx

GetLastInputInfo does not provide system-wide user input information across all running sessions. Rather, GetLastInputInfo provides session-specific user input information for only the session that invoked the function.

是否有类似的东西可以提供系统范围内的最后用户输入信息?

最佳答案

我相信做到这一点的唯一方法是 Hook 到 shell。

这是(显然)必须小心完成的事情,并且在操作系统完全支持之前(直到 windows 7)在托管代码中是不可行的,因此您将不得不使用一些非托管代码来实现这一点,也许从您的托管代码更新一些可查询的全局状态。 API 是 SetWindowsHookEx .

随着 Vista 的 session 隔离,您将需要更高的权限才能为其他 session 执行此操作。在这方面,从键盘记录器的工作方式中获取线索可能会有所帮助,但我没有现成的指向某些来源的链接。

这里的第一个开始是来自 condor 的 Windows 端口的源代码用于发现键盘事件:

/***************************************************************
*
* Copyright (C) 1990-2007, Condor Team, Computer Sciences Department,
* University of Wisconsin-Madison, WI.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You may
* obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
***************************************************************/


#include <windows.h>

// Shared DATA
// put in here data that is needed globally
#pragma data_seg(".SHARDATA")
HHOOK hHook = NULL;
LONG KBkeyhitflag = 0;
#pragma data_seg()
#pragma comment(linker, "/SECTION:.SHARDATA,RWS")

__declspec(dllexport) LRESULT CALLBACK KBHook(int nCode, WPARAM wParam,
LPARAM lParam)
{
InterlockedExchange(&KBkeyhitflag,1);

return CallNextHookEx(hHook,nCode,wParam,lParam);
}

HINSTANCE g_hinstDLL = NULL;

#if defined(__cplusplus)
extern "C" {
#endif //__cplusplus


int __declspec( dllexport) WINAPI KBInitialize(void)
{
hHook=(HHOOK)SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)KBHook,g_hinstDLL,0);
return hHook ? 1 : 0;
}

int __declspec( dllexport) WINAPI KBShutdown(void)
{
if ( UnhookWindowsHookEx(hHook) )
return 1; // success
else
return 0; // failure
}

int __declspec( dllexport) WINAPI KBQuery(void)
{
if ( InterlockedExchange(&KBkeyhitflag,0) )
return 1; // a key has been hit since last query
else
return 0; // no keys hit since asked last
}

#if defined(__cplusplus)
} // extern "C"
#endif //defined(__cplusplus)

BOOL WINAPI DllMain(HANDLE hInstDLL, ULONG fdwReason, LPVOID lpReserved)
{
switch (fdwReason)
{
case DLL_PROCESS_ATTACH:
g_hinstDLL = (HINSTANCE)hInstDLL;
DisableThreadLibraryCalls(g_hinstDLL);
break;
}
return 1;
}

关于c# - GetLastInputInfo 是用户特定的 - 是否有类似的东西可以提供机器范围的最后输入时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1219050/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com