title: C program to identify control or alt keypress
body: <p>I am trying to write a C program which is aware of the control / alt / shift key being pressed down.  I found something that provides this functionality in Java, but that's not helping me too much.  </p>
  
  <pre><code>void CMousepresentView::OnDraw(CDC* pDC)
  {
  int shiftValue=::GetKeyState(VK_SHIFT);
  if(!shiftValue)
  pDC-&gt;TextOut(0,50,"Shift not pressed");
  else
  pDC-&gt;TextOut(0,50,"Shift pressed");
  
  int ctrlValue=::GetKeyState(VK_CONTROL);
  if(!ctrlValue)
  pDC-&gt;TextOut(0,100,"Ctrl not pressed");
  else
  pDC-&gt;TextOut(0,100,"Ctrl pressed");
  }
  </code></pre>
  
  <p>So what I have so far is quite rudimentary but I must start somewhere.  It doesn't work though, at all.</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;ctype.h&gt;
  
  int main(void)
  {
    char ch;
  
    do {
      ch = getchar();
      putchar(ch);
    } while(iscntrl(ch));
    return 0;
  }
  </code></pre>
  
  <p>I was hoping that iscntrl would at least give me some reaction from the system to start debugging and identifying the control sequence keypresses.  No such luck.  </p>
  
  <p>If I could see an example that outputs "control is pressed / control is released", I could probably figure out the rest.</p>
  
  <p>Update:<br>
  Have had some progress with this <a href="http://www.thelinuxdaily.com/2010/05/grab-raw-keyboard-input-from-event-device-node-devinputevent/" rel="nofollow">http://www.thelinuxdaily.com/2010/05/grab-raw-keyboard-input-from-event-device-node-devinputevent/</a></p>
  
  <p>Update: </p>
  
  <p>I think the answer is in using xlib.  Thanks everyone.</p>