小编mic*_*ell的帖子

更好的方式以编程方式检测按键?

我目前正在使用这个:

while (1)
    {
        if (GetAsyncKeyState(VK_F1))
        {
        //do something
        }
    }
Run Code Online (Sandbox Code Playgroud)

检测用户是否按下某个键,在这种情况下为F1.我发现这会大大减少cpu的使用量,我的问题是,有没有更好的方法来检测按键?

c++ windows keypress

1
推荐指数
1
解决办法
649
查看次数

C++表达式必须具有类类型 - 字符串到const char*

尝试转换stringconst char*在底线给出"表达式必须具有类类型".尝试转换没有运气的一些变化.有任何想法吗?

string GetMachineID()
    {
        // LPCTSTR szHD = "C:\\";  // ERROR
        string ss;
        ss = "Err_StringIsNull";
        UCHAR szFileSys[255],
            szVolNameBuff[255];
        DWORD dwSerial;
        DWORD dwMFL;
        DWORD dwSysFlags;
        int error = 0;

        bool success = GetVolumeInformation(LPCTSTR("C:\\"), (LPTSTR)szVolNameBuff,
            255, &dwSerial,
            &dwMFL, &dwSysFlags,
            (LPTSTR)szFileSys,
            255);
        if (!success)
        {
            ss = "Err_Not_Elevated";
        }
        stringstream errorStream;
        errorStream << dwSerial;
        return string(errorStream.str().c_str());
    }

    const char *cstr = GetMachineID.c_str();
Run Code Online (Sandbox Code Playgroud)

.net c++ string char

0
推荐指数
1
解决办法
746
查看次数

标签 统计

c++ ×2

.net ×1

char ×1

keypress ×1

string ×1

windows ×1