c++监听键盘, C++模拟键盘输入

1、方案1:

#include <windows.h>
#include <conio.h>
#include <iostream>

using namespace std;

int main()
{
    system("chcp 65001 > nul");
    std::cout << "Hello, CSGO Cheater!" << std::endl;
    int ch;
    
    //方案1
    int stop = 1;
    int first = 0;
    while(true){
        if(stop == 0){
            std::cout << "I'm Cheating" << std::endl;
            
        }
        if(GetAsyncKeyState(VK_F12) && first){
            std::cout << "Stop!" << std::endl;
            stop = 1;
        }else if(GetAsyncKeyState(VK_F11)&& first){
            std::cout << "Cheatting" << std::endl;
            stop = 0;
        }
        first = 1;
    }

}

2、方案2:

#include <windows.h>
#include <conio.h>
#include <iostream>

using namespace std;

int main()
{
    system("chcp 65001 > nul");
    std::cout << "Hello, CSGO Cheater!" << std::endl;
    // 方案2
    int ch;
    while(true){
        if(_kbhit()){
            ch = _getch();
            cout << ch;
            if (ch == 27){
                break;
            }
        }
    }
    

}

这个完全没有反应啊。

不知道为什么!!!!

3、GetKeyState 和GetAsyncKeyState有什么区别?

GetKeyState()和GetAsyncKeyState()的区别_FlowShell的博客-CSDN博客_易语言getasynckeystate

写的非常好! 

4、参考材料

基本是这个逻辑

5、键盘编码

Virtual-Key Codes (Winuser.h) - Win32 apps | Microsoft Docs

posted @   bH1pJ  阅读(369)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
点击右上角即可分享
微信分享提示