• input


    #include<dinput.h>

    LPDIRECTINPUT8 directInput_;
    LPDIRECTINPUTDEVICE8 keyboardDevice_;
    char keyboardKeys_[256];
    char prevKeyboardKeys_[256];

    ///////////////////////Init//////////////////////
    ZeroMemory(keyboardKeys_,sizeof(keyboardKeys_));
    ZeroMemory(prevKeyboardKeys_,sizeof(prevKeyboardKeys_));

    HRESULT result = DirectInput8Create(hInstance_,DIRECTINPUT_VERSION,IID_IDirecctInput8,(void**)&directInput_,0);

    if(FAILED(result)) return false;

    result = directInput_->CreateDevice(GUID_SysKeyboard,&keyboardDevice_,0);

    if(FAILED(result)) return false;

    result = keyboardDevice_->SetDataFormat(&c_dfDKeyboard);
    if(FAILED(result)) return false;

    result = keyboardDevice_->SetCooperativeLevel(hsnd_,DISCL_FOREGROUND | DISCL_NONECXLUSIVE);
    if(FAILED(result)) return false;

    result = keyboardDevice_->Acquire();
    if(FAILED(result)) return false;


    /////////////////////Update/////////////////////////

    keyboardDevice_->GetDeviceState(sizeof(keyboardKeys_),(LPVOID)&keyboardKeys_);

    if(GetAsyncKeyState(VK_ESCAPE)) PostQuitMessage(0);

    if((prevKeyboardKeys_[DIK_DOWN)&0x80) && (keyboardKeys_[DIK_DOWN)&0x80))
    {
    }

    memcpy( prevKeyboardKeys_, keyboardKeys_, sizeof( keyboardKeys_ ) );

    作者:长风 Email:844064492@qq.com QQ群:607717453 Git:https://github.com/zhaohu19910409Dz 开源项目:https://github.com/OriginMEK/MEK 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利. 感谢您的阅读。如果觉得有用的就请各位大神高抬贵手“推荐一下”吧!你的精神支持是博主强大的写作动力。 如果觉得我的博客有意思,欢迎点击首页左上角的“+加关注”按钮关注我!
  • 相关阅读:
    Flask学习笔记(10):钩子函数
    Flask学习笔记(8):csrf攻防
    Flask学习笔记(7):flask-migrate
    Flask学习笔记(6):flask-script
    Flask学习笔记(5):session
    Flask学习笔记(4):cookie
    Flask学习笔记(3):上传文件
    WTForm表单验证
    WINDOWS CMD命令小集
    Alembic环境配置与基本操作
  • 原文地址:https://www.cnblogs.com/zhaohu/p/6995058.html
Copyright © 2020-2023  润新知