I am doing a work on project, during travelling I use my phone IDE (Cxxdroid) and when I am at home I use my laptop. For detection of keyboard input I utilize _getch().
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
#include <conio.h>
int main()
{
while (1)
{
if (_kbhit()) // <-- is this part redundant???
{
int keyboardInput;
keyboardInput = _getch();
std::cout << keyboardInput;
}
}
return 0;
}
On PC it works good, while pressing any key the value of numeric get printed quickly but on the other hand using cell phone when I press first key, nothing happens, we get no printing, After that we get first print with press of second key, third key give print of second value and it goes on in this way. I don’t know what’s going on my cell phone, If any one has any idea please tell me. I am following this tutorial: https://www.theengineeringprojects.com/2020/01/introduction-to-entity-framework-core.html Thanks.
One thing more about the _kbhit() the part of code is it unnecessary? With and without it, it operates fine; don’t know why we use it. Any idea?
Both _kbhit() and _getch() are windows functions. How do get it to work on Android/Linux?
One thing more about the _kbhit() the part of code is it unnecessary? With and without it, it operates fine; don’t know why we use it. Any idea?
_getch() is a blocking function. _kbhit() is used to prevent this blocking and doing other things like screen update. In your case it is currently unnecessary.