Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 功能计时器阻止主功能继续_C++_Loops_Keystroke - Fatal编程技术网

C++ 功能计时器阻止主功能继续

C++ 功能计时器阻止主功能继续,c++,loops,keystroke,C++,Loops,Keystroke,我是新来的。我的C++大学课堂上有点生疏。我正在尝试制作一个程序,其中特定的按键记录在cout中看到的文本。我遇到的问题是,定时器功能阻止了主功能继续。定时器功能可在延迟达到28时将Tic增加1定时器循环,当达到28时,延迟重置回0。为什么我的main没有继续?它是否正在等待计时器完成循环?如何使定时器和主同时工作?这不是家庭作业。做一个个人项目 #include <Windows.h> #include <iostream> #include <fstream&g

我是新来的。我的C++大学课堂上有点生疏。我正在尝试制作一个程序,其中特定的按键记录在cout中看到的文本。我遇到的问题是,定时器功能阻止了功能继续。定时器功能可在延迟达到28时将Tic增加1定时器循环,当达到28时,延迟重置回0。为什么我的main没有继续?它是否正在等待计时器完成循环?如何使定时器同时工作?这不是家庭作业。做一个个人项目

#include <Windows.h>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string>

using namespace std;

int Tic = 0;
int Delay = 0;

bool KeyIsListed(int iKey)
{
switch (iKey)
{
    case 0x41:
        cout << "ACS_Execute(10,0,0,0,0);\n"; //the A Note
        cout << "Delay("<<Tic<<");\n"; //Capture the time
        Delay = 0;
        Tic = 0
        break;
    case 0x53:
        cout << "ACS_Execute(11,0,0,0,0);\n"; //the S Note
        cout << "Delay("<<Tic<<");\n"; //Capture the time
        Delay = 0;
        Tic = 0
        break;
    case 0x44:
        cout << "ACS_Execute(12,0,0,0,0);\n"; //the D Note
        cout << "Delay("<<Tic<<");\n"; //Capture the time
        Delay = 0;
        Tic = 0
        break;
    case 0x46:
        cout << "ACS_Execute(13,0,0,0,0);\n"; //the F Note
        cout << "Delay("<<Tic<<");\n"; //Capture the time
        Delay = 0;
        Tic = 0
        break;
    case 0x47:
        cout << "ACS_Execute(14,0,0,0,0);\n"; //the G Note
        cout << "Delay("<<Tic<<");\n"; //Capture the time
        Delay = 0;
        Tic = 0
        break;
    case 0x48:
        cout << "ACS_Execute(15,0,0,0,0);\n"; //the H Note
        cout << "Delay("<<Tic<<");\n"; //Capture the time
        Delay = 0;
        Tic = 0
        break;
    case 0x4A:
        cout << "ACS_Execute(16,0,0,0,0);\n"; //the J Note
        cout << "Delay("<<Tic<<");\n"; //Capture the time
        Delay = 0;
        Tic = 0
        break;
    case 0x4B:
        cout << "ACS_Execute(17,0,0,0,0);\n"; //the K Note
        cout << "Delay("<<Tic<<");\n"; //Capture the time
        Delay = 0;
        Tic = 0
        break;
    case 0x4C:
        cout << "ACS_Execute(18,0,0,0,0);\n"; //the L Note
        cout << "Delay("<<Tic<<");\n"; //Capture the time
        Delay = 0;
        Tic = 0
        break;
    }
}

int timer()//Doom Tic timer
{
    while(TRUE)
    {
        if(Delay == 28)//Aprox to 1 tic
        {
            Delay = 0;//Reset delay to 0
            Tic ++;//Increase Tic by 1
        }
        else
        {
            Delay ++;//Increase Delay until it is at 28
        }
        Sleep(0.1);
    }
}

int main()
{
char key;
timer();//Call timer Function (This is preventing the main function from continuing)
while(TRUE)
{
    for(key = 8; key <= 190; key ++)
    {
        if(GetAsyncKeyState(key) == 1)
        {
            if(KeyIsListed(key) == FALSE)
            {

            }
        }
    }

}
return 0;
#包括
#包括
#包括
#包括
#包括
使用名称空间std;
int-Tic=0;
int延迟=0;
布尔键列表(int-iKey)
{
开关(iKey)
{
案例0x41:
库特
没有办法跳出这个循环。您的意思是在
if
块中放置
break
,还是
while(Delay>0)
(初始设置为1)


此外,如注释中所述,如果你说函数返回int,你需要确保它在每个路径上都有一个return语句。也许你只想
返回Tic;

请关注函数的最小部分。你是否使用了调试器或在
时间中加入了
cout
语句r
函数,以便您可以遵循逻辑?如果是,您观察到了什么?值得注意的是,您声明了
计时器
以返回
int
,但它当前未返回任何内容。这是未定义的行为。您应该确保您的警告处于可能的最高级别
  while(TRUE)
    {
        if(Delay == 28)//Aprox to 1 tic
        {
            Delay = 0;//Reset delay to 0
            Tic ++;//Increase Tic by 1
        }
        else
        {
            Delay ++;//Increase Delay until it is at 28
        }
        Sleep(0.1);
    }