我目前正在使用这个:
while (1)
{
if (GetAsyncKeyState(VK_F1))
{
//do something
}
}
Run Code Online (Sandbox Code Playgroud)
检测用户是否按下某个键,在这种情况下为F1.我发现这会大大减少cpu的使用量,我的问题是,有没有更好的方法来检测按键?
尝试转换string为const 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)