Hi friends i am doing the snake game program for Set top Box . I am Facing problem when i get the remote control keys.


if i press the up,down,right,left keys when program is running ,program does not response .once game is over then it is taking the values from keys.

Please help to solve this problem

Note : i am getting the keys through the MENU_GameKeys function,

and game starts at runsnake function

I post some parts of code here.........


Advance thanks for helping

Dani AI

Generated

Symptom reported by (remote presses during a running session only take effect after the session ends) points to an input-handling timing problem rather than game-logic or rendering math. The replies from are on point: the key API and the game loop interaction are the areas to inspect.

Common causes include:

  • The game loop blocks the system message pump or driver callbacks so key events are not delivered while the loop runs.
  • The code uses a blocking read that only returns when the loop yields, or it polls only at startup/teardown.
  • Keys are buffered by the driver and only drained later because the code never flushes the queue when a session starts.
  • Input calls are being made from the wrong thread (some STB SDKs require the main thread for key APIs).

Practical checks and fixes to try immediately:

  • Add lightweight logging inside the running loop that prints the raw key-read result and a timestamp each frame to confirm whether key reads occur in real time.
  • Replace any long blocking waits with a short per-frame sleep/yield so the platform can dispatch input. Example pseudocode:
    while (game_running) {
    k = pollKeyNonBlocking();     // read without blocking
    if (k != NO_KEY) handleKey(k);
    updateGameState();
    renderFrame();
    sleep_ms(16);                 // yield so driver/messages get processed
    }
  • On new-game start, flush the driver key queue (read until NO_KEY) so leftover presses from the previous session aren’t applied later.
  • If the SDK supports callbacks or a message pump, use that mechanism instead of tight polling. If moving input to a separate thread, confirm the SDK allows calls from threads other than the main thread and protect shared state.

As suggested, the exact driver semantics matter; the above steps are diagnostic and non-destructive ways to prove whether the loop or the input API is the root cause.

Recommended Answers

All 3 Replies

You're going to have to give more info, and preferably less code. What (non-standard) libaries are you using? For example, is FGS_GetCurrentKeyCode() a library function? Also, what does this mean exactly: "once game is over then it is taking the values from keys".

FGS_GetCurrentKeyCode() means some driver library function in set top box.

if i press the keys ,while running the game that time snake did not move according to the key directions..


Once game is over . Then it takes the key value and move according to the pressed key direction when i am running snake game again.


Please help me


Thanks

Yuvaraj.R

That's very strange. I don't know what the problem is.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.