Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
在调试过程中,我发现 SetCursorPos 无法可靠移动光标,虽然调用之后立刻查询光标位置没有问题,但经过一段时间后再次查询会发现光标位置又回到了设置之前。我怀疑这是因为 OS 异步处理硬件输入队列,SetCursorPos 时队列中仍有旧事件尚未处理。
现在使用 SendInput 将移动光标的事件插入输入队列,然后等待系统处理到该事件,避免了并发问题。如果设置不成功则多次尝试。这里旨在尽最大努力,因为这是 OS 的 bug,我怀疑是否有完美的解决方案。
经过测试,新方案似乎解决了问题,我没有再遇到光标跳跃的问题。