【问题标题】:Visual Studio hotkey detection on run运行时检测 Visual Studio 热键
【发布时间】:2019-10-26 12:05:01
【问题描述】:

也许很奇怪。无论如何在VS中启动项目后在运行时检测热键组合。

例如如果我按住 shift 并按 f5 或在 VS 中运行,那么我想触发一行特殊的代码。

如果您不按热键组合,则它会正常触发。

【问题讨论】:

    标签: visual-studio hotkeys compiler-directives


    【解决方案1】:

    (你用“visual studio”标记你的问题;我假设是 Windows 操作系统)

    换档:

    if(::GetAsyncKeyState(VK_SHIFT) < 0) // Shift down
    {
        // Do something ("special line of code") only if Shift down
    }
    

    大写锁定案例:

    SHORT nState = ::GetAsyncKeyState(VK_CAPITAL); // Caps Lock
    bool bToggled = nState & 1;
    bool bDown = nState & 0x8000;
    
    if (bToggled)
    {
        // Do something ("special line of code") only if Caps Lock toggled 
    }
    

    ...比如放在main()中

    --

    参考:GetAsyncKeyState()

    【讨论】:

      猜你喜欢
      • 2015-08-07
      • 2018-03-02
      • 2020-08-23
      • 2016-05-10
      • 2021-10-22
      • 1970-01-01
      • 1970-01-01
      • 2019-08-07
      • 2014-07-17
      相关资源
      最近更新 更多