- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
有时我会收到客户的错误报告,但我无法解释。在 Delphi 中的 Application.Run() 之后,我收到以下错误:
EOSError: System error: Code:_5 Access denied
Call Stack Information:
-------------------------------------------------------------------
|Address |Module |Unit |Class |Procedure |Line |
-------------------------------------------------------------------
|Running Thread: ID=4352; Priorität=0; Klasse=; [Main Thread] |
|-----------------------------------------------------------------|
|772B291F|USER32.dll | | |GetKeyState | |
|772B7B96|USER32.dll | | |GetPropA | |
|772B7B5A|USER32.dll | | |GetPropA | |
|772A7BC5|USER32.dll | | |DispatchMessageA| |
|772A7BBB|USER32.dll | | |DispatchMessageA| |
|00A6D804|Program.exe|Program.dpr| | |803[369]| // Application.Run
-------------------------------------------------------------------
和
EOsError: A call to an OS function failed
Call Stack Information:
-------------------------------------------------------------------
|Address |Module |Unit |Class |Procedure |Line |
-------------------------------------------------------------------
|Running Thread: ID=2712; Priorität=0; Klasse=; [Main Thread] |
|-----------------------------------------------------------------|
|7E379758|USER32.dll | | |GetCursorPos | |
|7E379ED9|USER32.dll | | |GetKeyState | |
|7E37B3FC|USER32.dll | | |CallNextHookEx | |
|7E380078|USER32.dll | | |GetPropA | |
|7E380042|USER32.dll | | |GetPropA | |
|7E3696C2|USER32.dll | | |DispatchMessageA| |
|7E3696B8|USER32.dll | | |DispatchMessageA| |
|00A6E823|Program.exe|Program.dpr| | |803[369]| //Application.Run
-------------------------------------------------------------------
在这两种情况下,从 Eurekalog 提交的屏幕截图都是全黑的。
任何人都可以解释一下,什么会导致 GetCursorPos 或 GetKeyState 以这种方式失败?
最佳答案
GetCursorPos
的文档说:
The input desktop must be the current desktop when you call GetCursorPos. Call OpenInputDesktop to determine whether the current desktop is the input desktop. If it is not, call SetThreadDesktop with the HDESK returned by OpenInputDesktop to switch to that desktop.
您可能会遇到这种情况,最常见的是在解锁工作站时。在我的代码中,我将 GetCursorPos
替换为以下变体:
function GetCursorPos(var lpPoint: TPoint): BOOL; stdcall;
(* The GetCursorPos API in user32 fails if it is passed a memory address >2GB
which breaks LARGEADDRESSAWARE apps. We counter this by calling GetCursorInfo
instead which does not suffer from the same problem.
In addition we have had problems with GetCursorPos failing when called
immediately after a password protected screensaver or a locked workstation
re-authenticates. This problem initially appeared with XP SP1 and is brought
about because TMouse.GetCursorPos checks the return value of the GetCursorPos
API call and raises an OS exception if the API has failed.
*)
var
CursorInfo: TCursorInfo;
begin
CursorInfo.cbSize := SizeOf(CursorInfo);
Result := GetCursorInfo(CursorInfo);
if Result then begin
lpPoint := CursorInfo.ptScreenPos;
end else begin
lpPoint := Point(0, 0);
end;
end;
您可以使用您最喜欢的代码 Hook 机制来替换 GetCursorPos
。我这样做是这样的:
RedirectProcedure(@Windows.GetCursorPos, @CodePatcher.GetCursorPos);
使用RedirectProcedure
,如下所述:Patch routine call in delphi
事实证明,对于我的特定场景,GetCursorPos
会失败,但 GetCursorInfo
不会失败。但正如评论中指出的那样,在某些情况下 GetCursorInfo
也会失败。在这种情况下,您可能会发现安排修补后的函数不返回 False
是很方便的。
至于GetKeyState
,我不确定。它很可能很相似,但 GetKeyState
是一个我个人并不熟悉的 API。
关于delphi - 解释 GetKeyState/GetCursorPos 的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20142166/
我希望在按下某个键时切换 bool 事件。具体来说,'s' 键。我已被指向函数 GetKeyState(),它应该在 Win32 API 下工作。我知道字母's'的ASCII码是115,所以我的代码如
我需要为我的小应用程序监听键盘按键状态。 #include #include #include using namespace std; int main() { while(1)
在VCL(Delphi 2010)中我使用这个函数来检查控制键是否被按下: function IsControlKeyPressed: Boolean; begin Result := GetKe
使用 GetKeyState,我可以在按下某个键时执行一些任务。但是,如果我有 if (GetKeyState(VK_UP) & 0x80),它会在整个按住键的过程中返回 true。 如果我只想在按下
大家好,我正在使用 C 中的代码块。我阅读了 https://msdn.microsoft.com/en-us/library/windows/desktop/ms646301(v=vs.85).as
当我使用 GetKeyState 或 GetAsyncKeyState 按下某些键时,我遇到了问题,两者都记录了按下键的历史记录。所以当我有一个 cin>> 这是我按下的键。 if(GetKeySta
我编写了一个简单的程序来监听大写锁定键,并显示一个消息框,说明当前大写锁定是打开还是关闭。 所以:用户按下大写锁定,程序确定大写锁定现在处于什么状态(打开或关闭)并显示一个消息框。 实际发生的是,当大
有时我会收到客户的错误报告,但我无法解释。在 Delphi 中的 Application.Run() 之后,我收到以下错误: EOSError: System error: Code:_5 Acce
Keyboard.GetKeyStates 似乎有一种方法可以返回错误按下的键,例如 Keyboard.GetKeyStates(Key.NumPad2) 可以返回 向下,切换,即使没有按下也是如此。
从MSDN ,我了解到GetKeyState 与当前线程的消息队列相关联。 然后我创建了两个示例应用程序:KeyPresser 和 BackChecker。 我在 KeyPresser 中按下一个键,
我正在使用 C# 开发一个简单的通用 Windows 应用程序。我有一个 RichEditBox,并且在使用 Control+I 组合键时发现了奇怪的行为,由于某种原因,它会插入一个 Tab(这是预期
我正在使用 C# 开发一个简单的通用 Windows 应用程序。我有一个 RichEditBox,并且在使用 Control+I 组合键时发现了奇怪的行为,由于某种原因,它会插入一个 Tab(这是预期
在下面的代码中:- BYTE ks[256]; auto keyboard_layout = GetKeyboardLayout(0); GetKeyboardState(ks); auto w =
与获得按键有什么区别: GetKeyState() GetAsyncKeyState() getch()? 我应该什么时候使用一个而不是另一个? 最佳答案 GetKeyState() 和 GetAsy
#include int main() { if ( !GetKeyState(VK_CAPITAL) & 1 ) { printf("caps off"); } else printf("caps
基本上, 它的灵感来自 Vim 我想使用一个键(例如 Alt、F1)组合(+I J K L)来映射到箭头键 Autohotkey 中已经完成的工作 Ralt & j::send{Left} Ralt
我是一名优秀的程序员,十分优秀!