c

How to generate key strokes events with the Input Subsystem

扶醉桌前 提交于 2021-02-19 06:15:47
问题 I am writing a Key board emulator program in Linux, As a start I was able to render key strokes into X11 window but this is not working in virtual terminals and try out a different way. I referred to http://thiemonge.org/getting-started-with-uinput and tried with uinput kernel module. According to the tutorial key strokes can be injected as a uinput event and I wrote below code accordingly. #include <stdio.h> #include <stdlib.h> #include <string.h> #include <unistd.h> #include <fcntl.h>

execve() failing to launch program in C

余生颓废 提交于 2021-02-19 06:15:40
问题 I am trying to spawn a new process using execve() from unistd.h on Linux. I have tried passing it the following parameters execve("/bin/ls", "/bin/ls", NULL); but get no result. I do not get an error either, the program just exits. Is there a reason why this is happening? I have tried launching it as root and regular user. The reason I need to use execve() is because I am trying to get it to work in an assembly call like so program: db "/bin/ls",0 mov eax, 0xb mov ebx, program mov ecx,

Detect window focus changes with XCB

无人久伴 提交于 2021-02-19 06:10:14
问题 I'm writing a program with XCB that needs to detect whenever a window gains or loses focus. So far I have this but it just hangs on the xcb_wait_for_event call, never entering the loop. What am I missing here to grab root events? Or am I just going about this totally wrong and there's a better way than listening to the root? #include <stdio.h> #include <stdlib.h> #include <xcb/xcb.h> int main (int argc, char **argv) { xcb_connection_t* conn = xcb_connect(NULL, NULL); if (xcb_connection_has

Order of memory allocation in C

淺唱寂寞╮ 提交于 2021-02-19 06:09:33
问题 I am trying to understand how the computer/OS/compiler (not sure who owns memory allocation, hence my noob-ish questioon) assigns memory addresses to local variables. I have this simple program: #include <stdio.h> int main(int argc, char** argv) { printf("hello, world\n"); int arr[10]; int a = 1; int b = 2; int c; for (int i = 0; i < 10; i++) { printf("Variable i: %p\n", &i); printf("Variable arr[i]: %p\n", &arr[i]); } printf("Variable a: %p\n", &a); printf("Variable b: %p\n", &b); printf(

Detect window focus changes with XCB

吃可爱长大的小学妹 提交于 2021-02-19 06:05:56
问题 I'm writing a program with XCB that needs to detect whenever a window gains or loses focus. So far I have this but it just hangs on the xcb_wait_for_event call, never entering the loop. What am I missing here to grab root events? Or am I just going about this totally wrong and there's a better way than listening to the root? #include <stdio.h> #include <stdlib.h> #include <xcb/xcb.h> int main (int argc, char **argv) { xcb_connection_t* conn = xcb_connect(NULL, NULL); if (xcb_connection_has

Order of memory allocation in C

梦想的初衷 提交于 2021-02-19 06:05:48
问题 I am trying to understand how the computer/OS/compiler (not sure who owns memory allocation, hence my noob-ish questioon) assigns memory addresses to local variables. I have this simple program: #include <stdio.h> int main(int argc, char** argv) { printf("hello, world\n"); int arr[10]; int a = 1; int b = 2; int c; for (int i = 0; i < 10; i++) { printf("Variable i: %p\n", &i); printf("Variable arr[i]: %p\n", &arr[i]); } printf("Variable a: %p\n", &a); printf("Variable b: %p\n", &b); printf(

What does major and minor mean in OpenGL with GLFW?

为君一笑 提交于 2021-02-19 06:05:26
问题 I was creating an OpenGL window with GLFW on some Dell PC that used integrated graphics. I thought that major means maximum and minor means minimum. However having a restricted version range of (3,3) works but a range that contains it such as (4,2) fails. Example: //fails glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); //fails glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2); //success glfwWindowHint

C freopen descriptor - close manually/leave opened

岁酱吖の 提交于 2021-02-19 06:01:33
问题 I've been using freopen (from stdio.h) function before without asking myself this question. But now I'm unsure. E.g. I've reopened stdout: #define OUTPUT_FILE "out.txt" if ( freopen(OUTPUT_FILE,"w+",stdout) == NULL) printf("logout can't be opened\n"); Usually every process has and handles stdout, stderr, stdin automatically and we needn't care about closing of them. But how is it to be here? I have reopened stdout. Should I call fclose for closing reopened stdout? PS I'd be gladder to look at

Detect keypress in console application?

旧巷老猫 提交于 2021-02-19 05:31:59
问题 I need to detect a keypress in a console application, without prompting the user. Basically, my app is normally a daemon that listens to a special input device, but i need to simulate it on a dev box using the keyboard in interactive mode. How can I do this? - Im on a Linux system. 回答1: If you can't block while waiting for input, then you can use e.g. select to check if the STDIN_FILENO file descriptor is ready for reading, and if it is then you can use normal input functions ( scanf , fgets

Detect keypress in console application?

血红的双手。 提交于 2021-02-19 05:31:35
问题 I need to detect a keypress in a console application, without prompting the user. Basically, my app is normally a daemon that listens to a special input device, but i need to simulate it on a dev box using the keyboard in interactive mode. How can I do this? - Im on a Linux system. 回答1: If you can't block while waiting for input, then you can use e.g. select to check if the STDIN_FILENO file descriptor is ready for reading, and if it is then you can use normal input functions ( scanf , fgets