3

I am linux user and would like to use these 'keyboard_event' functions, but the header for these functions is 'windows.h' and linux doesn't have any 'windows.h', so can anyone support some alternative header for these functions, or alternative way to simulate key press for linux ?

#include <iostream>
using namespace std;

int main() {

    keybd_event(VK_CONTROL,0x9d,0 , 0); //pressing CTRL
    keybd_event(VkKeyScan(‘R’),0x93,0 , 0); //pressing 'R'
    keybd_event(VkKeyScan(‘R’),0x93,KEYEVENTF_KEYUP,0); //releasing 'R'
    keybd_event(VK_CONTROL,0x9d,KEYEVENTF_KEYUP,0); /* releasing CTRL */


    return;
}
Cybber
  • 61
  • 3
  • 7
    You can't use the [keybd_event](https://msdn.microsoft.com/en-us/library/windows/desktop/ms646304(v=vs.85).aspx) function on Linux. Those are Windows / WinAPI specific libraries. – Ron Aug 12 '17 at 16:59
  • then what can I use to simulate keypress for linxu ? – Cybber Aug 12 '17 at 17:06
  • 1
    This is an XY problem; you are asking about how to implement a solution you have "invented". A better question would be to simply ask how to inject a keyboard event in Linux. – Clifford Aug 12 '17 at 17:09

3 Answers3

0

There's no "equivalent" for windows.h in Linux. You need to fix your errors case by case, or better, rewrite your code for Linux.

Reference: https://ubuntuforums.org/showthread.php?t=533304

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Farhad
  • 4,119
  • 8
  • 43
  • 66
0

The uinput kernel module and libevdev were introduced for exactly this purpose.

Murphy
  • 3,827
  • 4
  • 21
  • 35
0

I've found a solution, in code I just type:

system("xte 'keydown Control_L' 'key R' 'keyup Control_L'");

and it does the same, but <cstdlib> has to be included.

Cybber
  • 61
  • 3