Hi Folks,
I have stuck in problem. I want to record keyboard events like key up and key down in Linux OS but I couldnt able to find any proper answer.

I have got function but thats lib is very specific to Dev C++ in windows.

void GenerateKey(int vk , BOOL bExtended)
{
  KEYBDINPUT kb = {0};
  INPUT Input = {0};

  // generate down 
  if(bExtended)
    kb.dwFlags = KEYEVENTF_EXTENDEDKEY;
  kb.wVk = vk;  

  Input.type = INPUT_KEYBOARD;
  Input.ki = kb;
  ::SendInput(1, &Input, sizeof(Input));
  // generate up 
  ::ZeroMemory(&kb, sizeof(KEYBDINPUT));
  ::ZeroMemory(&Input, sizeof(INPUT));

  kb.dwFlags = KEYEVENTF_KEYUP;
  if(bExtended)
    kb.dwFlags |= KEYEVENTF_EXTENDEDKEY;

  kb.wVk = vk;
  Input.type = INPUT_KEYBOARD;
  Input.ki = kb;
  ::SendInput(1, &Input, sizeof(Input));
}

I exactly need code like this for my linux application.

Any ideas and suggestion will be of great help.

Thanks and regards,
jainp

Re: keyboard emulation function (C++) in linux OS ? 80 80

This is not keyboard emulation (which would be GENERATING key presses), but rather just catching key presses, right?

Apparently this can be done using curses:
http://www.codeguru.com/forum/showthread.php?t=435771

Re: keyboard emulation function (C++) in linux OS ? 80 80

Hi Daviddoria,
Thanks a lot for quick reply. But the thing is, I have already written the code to capture the key events using ncurses and that was pretty straightforward. But here What i want is to simulate keyevents. If u look deeper into the above code , the code is simulating key press UP and down, So i want something like that.

I may be wrong , but What i draw conclusion from the above code is its pressing key and not capturing.

Thanks

Be a part of the DaniWeb community

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