Question

I am working on a C++ project with K8055N USB interface board. What I have is a menu with possible selections of 1-4 and I want to be able to make selection by both - digital input and keyboard. At the moment I can achieve control ONLY by digital input OR keyboard. Here is a snapshot of working code for one selection option by digital input:

int select = 0;
while (select == 0)
{
bool d1 = ReadDigitalChannel(1); // ReadDigitalChannel(1) is checking hardware state of digital input 1
if (d1 == 1)
{
    select = 1;
    break;
}
}
switch (select)
{
case 1:
// the rest of the code

How and where can I add cin >> select to allow keyboard input as well or what are the alternatives that do not interrupt the loop?

Thanks

Was it helpful?

Solution

Just found a solution for it! I just said it to listen to keys being pressed using "OR ||". Example code:

if (d1 == 1 || GetAsyncKeyState(0x31) & 0x8000 || GetAsyncKeyState(0x61) & 0x8000)
{
select = 1;
break;
}

0x31 refers to the key address of button "1" and 0x61 is numpad 1.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top