Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. how detect "pressing key"

how detect "pressing key"

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
linuxquestioncareer
2 Posts 2 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Schehaider_Aymen
    wrote on last edited by
    #1

    Hi all, I m working with C under linux and i have a little prob :

    while(1)
    {
    if(scanf("%s", msg)>0)
    printf("Yr message is %s\n", msg);
    else
    /* some other Job */
    }

    but when i run the prog it still frozen waiting for the message but i wanna it do the other Job bloc. So is there any function that helps me detecting if there is a key pressed or no ??? Thx.

    "The Ultimate Limit Is Only Your Imagination."

    S 1 Reply Last reply
    0
    • S Schehaider_Aymen

      Hi all, I m working with C under linux and i have a little prob :

      while(1)
      {
      if(scanf("%s", msg)>0)
      printf("Yr message is %s\n", msg);
      else
      /* some other Job */
      }

      but when i run the prog it still frozen waiting for the message but i wanna it do the other Job bloc. So is there any function that helps me detecting if there is a key pressed or no ??? Thx.

      "The Ultimate Limit Is Only Your Imagination."

      S Offline
      S Offline
      Shyam Bharath
      wrote on last edited by
      #2

      I guess scanf is always returning a value > 0 in ur code. You would want to use a getch() like function to detect keypress rather than scanf. Check this out http://cboard.cprogramming.com/archive/index.php/t-27714.html[^]

      ------------------------------------------- It's code that drives you - Shyam

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups