简体   繁体   English

我可以将哪些C ++标头用于这些特定功能? Linux的

[英]What C++ header can I use for these specific functions ? Linux

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 ? 我是linux用户,想使用这些'keyboard_event'函数,但这些函数的标题是'windows.h'而linux没有'windows.h',所以任何人都可以支持这些函数的替代标题,或模拟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;
}

There's no "equivalent" for windows.h in Linux. Linux中的windows.h没有“等价”。 You need to fix your errors case by case, or better, rewrite your code for Linux. 你需要逐个修复你的错误,或者更好,重写你的Linux代码。

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

uinput内核模块和libevdev就是为了这个目的而引入的。

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. 并且它也是如此,但必须包含<cstdlib>

I don't know what "keyboard_event" functions are but i guess this would be helpful: 我不知道“keyboard_event”函数是什么,但我想这会有所帮助:

#include <iostream>
#include <cstdio> // for getchar()
#include <unistd.h> // for getch()
#include <termios.h> // for getch()

using namespace std;

int getch();
int main()
{
    int ch = getch();
    cout << ch << endl;
}

int getch()
{
    struct termios oldt, newt;
    int ch;
    tcgetattr(STDIN_FILENO, &oldt);
    newt = oldt;
    newt.c_lflag &= ~(ICANON | ECHO);
    tcsetattr(STDIN_FILENO, TCSANOW, &newt);
    ch = getchar();
    tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
    return ch;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM