Hello! hope everyone is fine.. I use code in c++ in UBUNTU (Linux) like below to read arrow keys for my functionality:
if(read(kfd, &c, 1) < 0)
but this captures Arrow keys as long as I press them...if I dont press any key , execution is blocked at read()...what I want is if I press keys it should execute their case in switch...but if I do nothing then it should execute some other code let say to call any other function...can anyone help please(need code in c++ for Ubuntu)...thanks in advance.
safdar from Austria
one thread will read the key..its okay...but the other thread will run freely and will call the function all the time no matter whether I press the key or not...My problem is that program should read the arrow keys and send commands Forward,Backward,Up and Down depending upon the key...but when I dont press any key it must send command STOP.
if one thread for all four movements...and one thread for STOP then there will be no motion because of freely sending Stop command by the second thread....
Simply saying...I have to control a Robot...I say code must send Stop command all the time but should also read the key....as soon as key is pressed it should leave the stop and should give motion command, and when key is released it should again start sending Stop command and also should wait for the arrow key press...
may this problem be fixed..
yes this idea was there in my mind but I cannot understand when to send STOP command because the execution of program blocks on read(). How to bypass read() and call the stop command. Can you please send me little code so that I can understand. Thanks for your guidance.
Safdar from Austria