Я новенький здесь. Немного заржавел после курса C++ в колледже. Я пытаюсь создать программу, в которой определенные нажатия клавиш регистрируют текст, увиденный в cout. Проблема, с которой я столкнулся, заключается в том, что функция timer препятствует продолжению работы функции main. Функция таймер увеличивает Tic на 1 каждый раз, когда Delay достигает 28. таймер зацикливается, и когда он достигает 28, Задержка сбрасывается до 0. Почему моя основная не продолжается? Может ли быть так, что он ожидает завершения цикла timer? Как заставить таймер и основной работать одновременно? Это не домашнее задание. Создание личного проекта.
#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;
}
cout
в функциюtimer
, чтобы следовать логике? Что вы заметили, если да? - person Tas   schedule 26.07.2018timer
для возвратаint
, но в настоящее время он ничего не возвращает. Это неопределенное поведение. Вы должны убедиться, что ваши предупреждения находятся на максимально возможном уровне. - person Tas   schedule 26.07.2018