在 Visual C++ 中模拟按键

发布于 2024-09-12 00:53:09 字数 809 浏览 6 评论 0原文

好吧,我可能完全搞错了,因为我不太了解 Windows 编程,但这里是。

我正在尝试在 Visual Studio 2010 的 C++ 项目中启动模拟按键。

本质上,当程序从另一个应用程序接收到特定的代码字符串时(这一切都是通过许多 if 语句进行的,凌乱但有效),

我需要它来执行与我按下键盘上的 control 和 s 的功能相同。

现在我发现的一些代码是这样的。

keybd_event(VK_LCONTROL,0,0,0); 
  keybd_event(bKey, 0, 0, 0);


   keybd_event(bKey, 0, KEYEVENTF_KEYUP, 0);
  keybd_event(VK_LCONTROL,0,KEYEVENTF_KEYUP,0); 

其中 bKey 是 S 的适当 ASCII 代码,我一下子就忘记了它,但它仍然与本文无关。

根据我的理解,这应该做什么

Push Control down
Push S down
Release S
Release Control.

但是它似乎没有这样做,它似乎只是按下并释放 S 从而根据当时是否有文本输入可用来打印 S 。

我在这里是不是完全找错了树?我知道如何在 Xcode 中的 Objective C 中执行此操作,但两者似乎完全不同,我知道它们是不同的系统,但仍然如此。

任何人都可以提出解决方案吗?基本上是一种让程序同时按下 Control + S 的方法(不是一个接一个,一起按下)。

非常感谢任何帮助。那里似乎有很多相互矛盾的信息。

Ok so I might be totally barking up the wrong tree here as I'm not that up to date on Windows programming but here goes.

I'm trying to initiate a simulated keypress in a C++ project in Visual Studio 2010.

Essentially when the program receives a specific code string from another application (which is all being worked via many if statements, messy but works)

I need it to perform the same function as if I pressed control and s on my keyboard.

Now some code I found was this.

keybd_event(VK_LCONTROL,0,0,0); 
  keybd_event(bKey, 0, 0, 0);


   keybd_event(bKey, 0, KEYEVENTF_KEYUP, 0);
  keybd_event(VK_LCONTROL,0,KEYEVENTF_KEYUP,0); 

Whereby bKey is the appropriate ASCII code for S, it escapes me off hand but still, it's mostly irrelevant to this post.

What this should do by my understanding of it is

Push Control down
Push S down
Release S
Release Control.

However it does not seem to do this, it seems to only push down and release S thereby printing S as appropriate or not depending if text entry is available at the time.

Am I barking up the wrong tree altogether here? I know how to do this in Objective C in Xcode but the two seem quite radically different, I know they're different systems but still.

Can anyone propose a solution to this? Basically a way to make the program hit Control + S together (not one after the other, together).

Any help is much appreciated. There seems to be a lot of conflicting information out there.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

与往事干杯 2024-09-19 00:53:09

试试这个:

keybd_event(VK_LCONTROL,MapVirtualKey(VK_LCONTROL,0),0,0); 
keybd_event(bKey, MapVirtualKey(bKey,0), 0, 0);


keybd_event(bKey, MapVirtualKey(bKey,0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_LCONTROL,MapVirtualKey(VK_LCONTROL,0),KEYEVENTF_KEYUP,0); 

Try this instead:

keybd_event(VK_LCONTROL,MapVirtualKey(VK_LCONTROL,0),0,0); 
keybd_event(bKey, MapVirtualKey(bKey,0), 0, 0);


keybd_event(bKey, MapVirtualKey(bKey,0), KEYEVENTF_KEYUP, 0);
keybd_event(VK_LCONTROL,MapVirtualKey(VK_LCONTROL,0),KEYEVENTF_KEYUP,0); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文