kwhat / libuiohook Goto Github PK
View Code? Open in Web Editor NEWA multi-platform C library to provide global keyboard and mouse hooks from userland.
License: Other
A multi-platform C library to provide global keyboard and mouse hooks from userland.
License: Other
When USE_XKB is not defined in config.h, them related headers are not included, for example in input_hook.c:
#ifdef USE_XKB
#include <xcb/xkb.h>
#include <X11/XKBlib.h>
#endif
However, if they are not included the compilation fails:
./input_hook.c:168:47: error: ‘XkbUseCoreKbd’ undeclared (first use in this function)
if (XkbGetIndicatorState(hook->ctrl.display, XkbUseCoreKbd, &led_mask) == Success) {
^
./input_hook.c:168:47: note: each undeclared identifier is reported only once for each function it appears in
./input_hook.c: In function ‘hook_event_proc’:
./input_hook.c:317:4: warning: implicit declaration of function ‘xkb_state_update_key’ [-Wimplicit-function-declaration]
xkb_state_update_key(state, keycode, XKB_KEY_DOWN);
^
./input_hook.c:317:25: error: ‘state’ undeclared (first use in this function)
xkb_state_update_key(state, keycode, XKB_KEY_DOWN);
^
./input_hook.c:317:41: error: ‘XKB_KEY_DOWN’ undeclared (first use in this function)
xkb_state_update_key(state, keycode, XKB_KEY_DOWN);
^
./input_hook.c:412:41: error: ‘XKB_KEY_UP’ undeclared (first use in this function)
xkb_state_update_key(state, keycode, XKB_KEY_UP);
If being run in a headless environment, e.g. through ssh or with an application that's being unit tested on a CI server, libuiohook causes a segfault during library load:
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff5ada378 in XkbGetUpdatedMap () from /usr/lib/x86_64-linux-gnu/libX11.so.6
(gdb) bt
#0 0x00007ffff5ada378 in XkbGetUpdatedMap () at /usr/lib/x86_64-linux-gnu/libX11.so.6
#1 0x00007ffff5ada4a5 in XkbGetMap () at /usr/lib/x86_64-linux-gnu/libX11.so.6
#2 0x00007ffff5a3e106 in load_input_helper (disp=0x0) at src/x11/input_helper.c:1801
#3 0x00007ffff5a3da2b in on_library_load () at src/x11/system_properties.c:475
#4 0x00007ffff7fe0b8a in call_init (l=<optimized out>, argc=argc@entry=1, argv=argv@entry=0x7fffffffe428, env=env@entry=0x7fffffffe438) at dl-init.c:72
#5 0x00007ffff7fe0c91 in call_init (env=0x7fffffffe438, argv=0x7fffffffe428, argc=1, l=<optimized out>) at dl-init.c:30
#6 _dl_init (main_map=0x7ffff7ffe190, argc=1, argv=0x7fffffffe428, env=0x7fffffffe438) at dl-init.c:119
#7 0x00007ffff7fd013a in _dl_start_user () at /lib64/ld-linux-x86-64.so.2
If this registration could be delayed until hook_run
or a new setup API is called, then the application could choose to not start hook and avoid the call. As it is now, the application has to avoid linking hook, and instead load the library from code once it's verified that there's a normal display present.
Most of the posted issues are compiling process related.
Maybe we could use something like Travis (https://docs.travis-ci.com/user/getting-started/ | https://docs.travis-ci.com/user/languages/cpp/) to automatically built the binaries on each release and attach them in releases page section (https://github.com/kwhat/libuiohook/releases)
hi,
Now that I got it working on windows, I'm back to trying on arch linux. However, when I run make (no configure errors this time, whew), it gives the following output:
/bin/sh ./libtool --tag=CC --mode=link gcc -std=gnu99 -Wall -Wextra -pedantic -Wno-unused-parameter -I./include -I./src/x11 -I./src -g -O2 -Wl,--no-undefined -Wl,--no-undefined -o libuiohook.la -rpath /usr/local/lib src/libuiohook_la-logger.lo src/x11/libuiohook_la-input_helper.lo src/x11/libuiohook_la-input_hook.lo src/x11/libuiohook_la-post_event.lo src/x11/libuiohook_la-system_properties.lo -lXinerama -lXt -lX11 -lXtst -lXtst -lX11
libtool: link: gcc -std=gnu99 -shared -fPIC -DPIC src/.libs/libuiohook_la-logger.o src/x11/.libs/libuiohook_la-input_helper.o src/x11/.libs/libuiohook_la-input_hook.o src/x11/.libs/libuiohook_la-post_event.o src/x11/.libs/libuiohook_la-system_properties.o -lXinerama -lXt -lXtst -lX11 -g -O2 -Wl,--no-undefined -Wl,--no-undefined -Wl,-soname -Wl,libuiohook.so.0 -o .libs/libuiohook.so.0.0.0
src/x11/.libs/libuiohook_la-input_hook.o: In function hook_event_proc': /home/lilmike/prog/libuiohook/src/x11/input_hook.c:589: undefined reference to
hook_get_screen_info'
collect2: error: ld returned 1 exit status
Makefile:695: recipe for target 'libuiohook.la' failed
make: *** [libuiohook.la] Error 1
Anyone know what that could be about?
-Michael.
Thanks!
I am using the Node package iohook
which leverages libuiohook
. The original issue was here for context. However, now that I can run iohook on the UDOO Quad ARM computer locally when run from the terminal on the physical machine, I cannot run iohook when invoking the app from a remote computer via SSH.
I was told this was an libuiohook
issue so here I am.
The usage example iohook
provides works when run from the terminal on the actual machine with a monitor, keyboard and mouse.
However, when disconnecting the monitor and keyboard (and even with them connected) and SSHing into the UDOO, I get this when running the usage example:
on_library_load [456]: XOpenDisplay failure!
load_input_helper [1907]: XkbGetKeyboard failed to locate a valid keyboard!
PID 7608 received SIGSEGV for address: 0x94
Error: Couldn't find per display information
Also, the intent is for this to be run on an UDOO Quad without a monitor or mouse connected, just a USB button which essentially acts as a keyboard.
Doing the reverse and SSHing into my Mac from the UDOO, I am able to run the usage example remotely on my Mac and press the USB button connected to the Mac and get the keyup event. However, doing the opposite and SSHing into my UDOO from the Mac and running the usage example provides the above error. Any ideas?
ARM-based devices running Windows currently require 32-bit (x86) builds.
When using libuiohook
in this environment (I'm testing against ia32 architecture on win32) pVkToWcharTable
is null when accessed within input_helper
. I believe this is due to an issue with pointer sizes.
This Stackoverflow post seems related to what's happening here. The answer indicates that utilizing the original kbd.h
would work in 32-bit environments.
I did manage to populate pVkToWcharTable
by making changes to input_helper.h
using the original definitions fromkbd.h
, but it seems there needs to be further changes inside keycode_to_unicode
to accommodate a 32-bit environment.
I hope helps. This is a bit outside my competency, but I'm happy to test and provide feedback.
Is there a plan to add touch event support ? Thanks very much.
Hello!
First of all, thanks for the great library!
I'm trying to use libuiohook with simple Qt program under OS X.
And sometimes the library starts sending EVENT_KEY_TYPED constantly.
As the result my program freezes.
I can't reproduce this bug in demo_hook app, but in my Qt app the problem arise regularly.
Here is how I'm using the library: (http://ns35.ru/tmp/hooks.cpp)
I'm starting it in separate thread.
And some logs:
(http://ns35.ru/tmp/log_failed.txt)
(http://ns35.ru/tmp/log_failed2.txt)
(http://ns35.ru/tmp/log_failed3.txt)
(http://ns35.ru/tmp/log_normal.txt)
When I had removed lines 327-395 in /libuiohook-master/src/darwin/input_hook.c the problem gone.
The problem reproduced in master and 1.0 branches, in OS X 9 and OS X 10, in debug and release library builds. The problem persists in builds with --disable-corefoundation and --disable-iokit.
I solved my problem because I don't need EVENT_KEY_TYPED messages, but I report anyway in case this would help somebody.
Hello,
I'm facing some problems on Windows ( i didn't test on other platform yet). some keys doesn't trigger KEY_TYPED
event. I'm talking here about PageUp/PageDown, Del/Insert, Home/End and F1,F2,... function keys.
KEY_RELEASED
and KEY_PRESSED
work correctly.
Regards,
[~/libuiohook]$ ./bootstrap.sh
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal -I /opt/local/share/aclocal --force -I m4
aclocal: warning: couldn't open directory '/opt/local/share/aclocal': No such file or directory
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/local/Cellar/autoconf/2.69/bin/autoconf --include=/opt/local/share/aclocal --force
configure.ac:76: error: possibly undefined macro: AC_PROG_LIBTOOL
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
configure.ac:99: error: possibly undefined macro: AC_LIBTOOL_WIN32_DLL
autoreconf: /usr/local/Cellar/autoconf/2.69/bin/autoconf failed with exit status: 1
The demo program failed to build on macOS with error
error: use of undeclared identifier 'wint_t'
I was able to fix the error and compile successfully by including wchar.h
in demo_hook.c
diff --git a/src/demo_hook.c b/src/demo_hook.c
index 0256059..8d5bfe3 100644
--- a/src/demo_hook.c
+++ b/src/demo_hook.c
@@ -26,6 +26,7 @@
#include <stdio.h>
#include <string.h>
#include <uiohook.h>
+#include <wchar.h>
bool logger_proc(unsigned int level, const char *format, ...) {
bool status = false;
Hi,
I was just trying to compile libuiohook for a project I'm working on, and based on a comment to an issue on jninativehook, I needed to use msys2. I installed the packages mentioned in the issue, and did autoconf. The following output resulted:
configure.ac:59: error: possibly undefined macro: AM_INIT_AUTOMAKE
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
configure.ac:76: error: possibly undefined macro: AC_PROG_LIBTOOL
configure.ac:100: error: possibly undefined macro: AC_LIBTOOL_WIN32_DLL
configure.ac:369: error: possibly undefined macro: AM_CONDITIONAL
I tried automake, but it said to run autoconf again.
-Michael.
So, I have been trying to trace the problem I have been having with jnativehook.
I made my own hotkey listener just using libuiohook and I modeled the listener after demo_hook.c
When I run demo_hook.c and do a side scroll using my macs trackpad, I get a floating point exception. Here is example output
id=9,when=47596744929742,mask=0xA000,x=295,y=163,button=0,clicks=0
id=9,when=47596762488362,mask=0xA000,x=297,y=163,button=0,clicks=0
id=9,when=47596780017010,mask=0xA000,x=298,y=163,button=0,clicks=0
id=9,when=47596797004642,mask=0xA000,x=301,y=163,button=0,clicks=0
id=9,when=47596813966610,mask=0xA000,x=303,y=163,button=0,clicks=0
id=9,when=47596831185952,mask=0xA000,x=305,y=164,button=0,clicks=0
fish: './a.out' terminated by signal SIGFPE (Floating point exception)
MacOS v10.11.5
Anyone knows why I got the following error while trying to build and run it from CLion IDE?
/Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/mazik/Desktop/libuiohook/cmake-build-debug --target demo_properties -- -j 2
make[3]: *** No rule to make target `CMakeFiles/uiohook.dir/build'. Stop.
make[2]: *** [CMakeFiles/uiohook.dir/all] Error 2
make[1]: *** [CMakeFiles/demo_properties.dir/rule] Error 2
make: *** [demo_properties] Error 2
I tried to configure project using CMake but it seem that config.h.in
not found.
CMake Error: File D:/work/libuiohook/include/config.h.in does not exist.
CMake Error at CMakeLists.txt:65 (configure_file):
configure_file Problem configuring file
The aclocal
is no longer exists on the following:
Line 4 in 5d60196
The new path should be include=" -I/usr/local/share/aclocal"
Hi,
we tray integrate libuiohook with Qt app and when we run app and close is we have error:
get_keyboard_layout_file [455]: RegOpenKeyEx failed to open key: "SYSTEM\CurrentControlSet\Control\Keyboard Layouts\0"!
21:07:19: The program has unexpectedly finished.
21:07:19: The process was ended forcefully.
Can you tell me what is problem. We test on win 10 and win 7 not different.
I use: demo_hook_async.c
Thanks!
Per "input_helper.h", I'm filing a bug report because Visual Studio 2013 Community Edition (_MSC_VER == 1800) does not define LPFN_ISWOW64PROCESS.
Hi,
I have been working with libuiook in linux for a while now, firts fo all thanks for making this great lib.
However, I need to make it run in windows, but I'm having problems installing libuiohook in windows.
This it's what I've done so far:
I install MinGW and MSYS2 and follow the step in this link
https://github.com/kwhat/jnativehook/wiki/Compiling.
After that I continue with:
./bootstrap.sh
./configure
make && make install
Everything work perfectly until the last step make && make install, when I got this error:
src/windows/input_hook.c:638:8: error: 'EVENT_OBJECT_NAMECHANGE' undeclared (first use in this function)
case EVENT_OBJECT_NAMECHANGE:
^
src/windows/input_hook.c:638:8: note: each undeclared identifier is reported only once for each function it appears in
src/windows/input_hook.c: In function 'hook_run':
src/windows/input_hook.c:705:2: warning: implicit declaration of function 'SetWinEventHook' [-Wimplicit-function-declaration]
win_event_hhook = SetWinEventHook(
^
src/windows/input_hook.c:706:4: error: 'EVENT_OBJECT_NAMECHANGE' undeclared (first use in this function)
EVENT_OBJECT_NAMECHANGE, EVENT_OBJECT_NAMECHANGE,
^
src/windows/input_hook.c:710:4: error: 'WINEVENT_OUTOFCONTEXT' undeclared (first use in this function)
WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
^
src/windows/input_hook.c:710:28: error: 'WINEVENT_SKIPOWNPROCESS' undeclared (first use in this function)
WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS);
^
Makefile:917: recipe for target 'src/windows/libuiohook_la-input_hook.lo' failed
make: *** [src/windows/libuiohook_la-input_hook.lo] Error 1
I really have no idea what could be caussing this error, I'm using the 1.0 version of the libuiohook.
Any idea of what could be caussing this error ??
Hi Alex Barker (@kwhat), I have one problem with deadkeys support.
Some keys works fine, for example: ?¿@{} -> The keychar is correct: id=3,when=15251484,mask=0x1,keychar=?,rawcode=219
But when I try with a deadkey + letter dont works. For example: Á
id=4,when=16440134,mask=0x0,keycode=40,rawcode=0xDE
id=5,when=16440196,mask=0x0,keycode=40,rawcode=0xDE
id=4,when=16440258,mask=0x0,keycode=30,rawcode=0x41
id=3,when=16440258,mask=0x0
id=5,when=16440336,mask=0x0,keycode=30,rawcode=0x41
It only logs A (0x41) without UTF-16 composition.
I tried to compile the project on a Mac OSX 10.9.3 and got an error at:
https://github.com/kwhat/libuiohook/blob/master/src/darwin/input_helper.c#L307
src/darwin/input_helper.c:307:2: error: use of undeclared identifier 'VC_HELP'
VC_HELP, // 114 kVK_Help
^
1 error generated.
make: *** [src/darwin/libuiohook_la-input_helper.lo] Error 1
VC_HELP is not contained in
https://github.com/kwhat/libuiohook/blob/master/include/uiohook.h
I managed to resolve the error by inserting VC_HELP into uiohook.h
#define VC_HELP 0x0072
The 0x0072 is just a bogus value since I have no clue what a Help-keycode on a Mac is nor if a help-key even exists.
Windows mouse coordinates need to be normalized as due to MOUSEEVENTF_ABSOLUTE (1)
If MOUSEEVENTF_ABSOLUTE value is specified, dx and dy contain normalized absolute coordinates between 0 and 65,535. The event procedure maps these coordinates onto the display surface. Coordinate (0,0) maps onto the upper-left corner of the display surface; coordinate (65535,65535) maps onto the lower-right corner. In a multimonitor system, the coordinates map to the primary monitor.
I'll split the issue in two versions as for the single monitor version the fix is straightforward.
Single monitor:
It can be easily fixed by normalizing the coordinates this way:
double fScreenWidth = GetSystemMetrics( SM_CXSCREEN )-1;
double fScreenHeight = GetSystemMetrics( SM_CYSCREEN )-1;
...
events[events_size].mi.dx = event->data.mouse.x * (65535.0f/fScreenWidth);
events[events_size].mi.dy = event->data.mouse.y * (65535.0f/fScreenHeight);
...
events[events_size].mi.dx = event->data.wheel.x * (65535.0f/fScreenWidth);
events[events_size].mi.dy = event->data.wheel.y * (65535.0f/fScreenHeight);
Multiple monitor:
We need to know to which monitor the coordinates x,y belong to in order to make the conversion properly as it depends on the monitor resolution (in case they are non-uniform).
So from post_event we need access to the monitor enumerator or to a valid screen_info structure.
P.S. I'll be also opening a ticket for the hook_create_screen_info (as you were done with it already?)
(1):
https://msdn.microsoft.com/en-us/library/windows/desktop/ms646273(v=vs.85).aspx
I get the following trying to run make
in the ./boostrap.sh, ./configure, make && make install
process from the docs.
> make
/bin/sh ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I./include -Wall -Wextra -pedantic -Wno-unused-parameter -I./include -I./src/darwin -I./src -g -O2 -MT src/libuiohook_la-logger.lo -MD -MP -MF src/.deps/libuiohook_la-logger.Tpo -c -o src/libuiohook_la-logger.lo `test -f 'src/logger.c' || echo './'`src/logger.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I./include -Wall -Wextra -pedantic -Wno-unused-parameter -I./include -I./src/darwin -I./src -g -O2 -MT src/libuiohook_la-logger.lo -MD -MP -MF src/.deps/libuiohook_la-logger.Tpo -c src/logger.c -fno-common -DPIC -o src/.libs/libuiohook_la-logger.o
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I./include -Wall -Wextra -pedantic -Wno-unused-parameter -I./include -I./src/darwin -I./src -g -O2 -MT src/libuiohook_la-logger.lo -MD -MP -MF src/.deps/libuiohook_la-logger.Tpo -c src/logger.c -o src/libuiohook_la-logger.o >/dev/null 2>&1
mv -f src/.deps/libuiohook_la-logger.Tpo src/.deps/libuiohook_la-logger.Plo
/bin/sh ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I./include -Wall -Wextra -pedantic -Wno-unused-parameter -I./include -I./src/darwin -I./src -g -O2 -MT src/darwin/libuiohook_la-input_helper.lo -MD -MP -MF src/darwin/.deps/libuiohook_la-input_helper.Tpo -c -o src/darwin/libuiohook_la-input_helper.lo `test -f 'src/darwin/input_helper.c' || echo './'`src/darwin/input_helper.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I./include -Wall -Wextra -pedantic -Wno-unused-parameter -I./include -I./src/darwin -I./src -g -O2 -MT src/darwin/libuiohook_la-input_helper.lo -MD -MP -MF src/darwin/.deps/libuiohook_la-input_helper.Tpo -c src/darwin/input_helper.c -fno-common -DPIC -o src/darwin/.libs/libuiohook_la-input_helper.o
src/darwin/input_helper.c:117:16: warning: 'AXAPIEnabled' is deprecated: first deprecated in OS X 10.9 [-Wdeprecated-declarations]
is_enabled = AXAPIEnabled();
^
/System/Library/Frameworks/ApplicationServices.framework/Frameworks/HIServices.framework/Headers/AXUIElement.h:49:16: note: 'AXAPIEnabled' has been explicitly marked deprecated here
extern Boolean AXAPIEnabled (void) CF_DEPRECATED_MAC(10_0, 10_9);
^
1 warning generated.
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I./include -Wall -Wextra -pedantic -Wno-unused-parameter -I./include -I./src/darwin -I./src -g -O2 -MT src/darwin/libuiohook_la-input_helper.lo -MD -MP -MF src/darwin/.deps/libuiohook_la-input_helper.Tpo -c src/darwin/input_helper.c -o src/darwin/libuiohook_la-input_helper.o >/dev/null 2>&1
mv -f src/darwin/.deps/libuiohook_la-input_helper.Tpo src/darwin/.deps/libuiohook_la-input_helper.Plo
/bin/sh ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I./include -Wall -Wextra -pedantic -Wno-unused-parameter -I./include -I./src/darwin -I./src -g -O2 -MT src/darwin/libuiohook_la-input_hook.lo -MD -MP -MF src/darwin/.deps/libuiohook_la-input_hook.Tpo -c -o src/darwin/libuiohook_la-input_hook.lo `test -f 'src/darwin/input_hook.c' || echo './'`src/darwin/input_hook.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I./include -Wall -Wextra -pedantic -Wno-unused-parameter -I./include -I./src/darwin -I./src -g -O2 -MT src/darwin/libuiohook_la-input_hook.lo -MD -MP -MF src/darwin/.deps/libuiohook_la-input_hook.Tpo -c src/darwin/input_hook.c -fno-common -DPIC -o src/darwin/.libs/libuiohook_la-input_hook.o
src/darwin/input_hook.c:321:6: warning: implicit declaration of function 'sysinfo' is invalid in C99 [-Wimplicit-function-declaration]
if (sysinfo(&sys_info) == 0) {
^
src/darwin/input_hook.c:321:15: error: use of undeclared identifier 'sys_info'; did you mean 'sysinfo'?
if (sysinfo(&sys_info) == 0) {
^~~~~~~~
sysinfo
src/darwin/input_hook.c:321:6: note: 'sysinfo' declared here
if (sysinfo(&sys_info) == 0) {
^
src/darwin/input_hook.c:322:15: error: use of undeclared identifier 'sys_info'; did you mean 'sysinfo'?
timestamp = sys_info.uptime;
^~~~~~~~
sysinfo
src/darwin/input_hook.c:321:6: note: 'sysinfo' declared here
if (sysinfo(&sys_info) == 0) {
^
src/darwin/input_hook.c:322:23: error: member reference base type 'int ()' is not a structure or union
timestamp = sys_info.uptime;
~~~~~~~~^~~~~~~
src/darwin/input_hook.c:1086:17: error: conflicting types for 'hook_run'
UIOHOOK_API int hook_run() {
^
./include/uiohook.h:423:18: note: previous declaration is here
UIOHOOK_API int hook_run(uint16_t listen_mask);
^
1 warning and 4 errors generated.
make: *** [src/darwin/libuiohook_la-input_hook.lo] Error 1
I'm actually trying to compile jnativehooks for use with java but this library is preventing the process. Any help would be appreciated as it seems you have a great library that I would love to try using.
I'm trying to install JnativeHook, and during the installation process it must install libuihook, and I've installed all the prerequisites of JNativeHook and libuihook (I think so).
After so many attempts, finally the compilation began and failed again. I don't know what more to do, I will let a screenshot here
Hi,
I read that visual studio 2015 has c99 support, and I even managed to compile libuiohook on it (using the command line). I was just thinking that perhaps an official project could be provided in the git repo now that visual studio does support c99.
-Michael.
Hi,
I am using allegro to get keyboard input, and really all I wanted was to get a keyboard hook on all platforms (as I am making mainly audiogames, aimed at the blind, and some screen readers, namely jaws for windows, hog the keyboard unless turned off, or an application specific hook set to override its hook). However, when I run my program with libuiohook installed, I get a bunch of log messages (btw, how to make those go away?), and allegro doesn't get any keyboard input. Any way to make allegro play nice with libuiohook?
Thanks,
-Michael.
I had to install the following unlisted dependencies in order to get ./configure to not error
xtst
xkbcommon-x11
xkbfile
Hi,
While compiling on Windows 7, mingw32 4.8.1, I get undeclared variables and functions errors:
EVENT_OBJECT_NAMECHANGE
WINEVENT_OUTOFCONTEXT
WINEVENT_SKIPOWNPROCESS
...
SetWinEventHook
UnhookWinEvent
I had to define WINVER macro in input_hook.c in order to compile successfully.
#ifndef WINVER
#define WINVER 0x0500
#endif
Following the negative coordinates, the issue also occurs into the other screen direction, reporting values higher than the maximum resolution itself. For now I'm dealing with this on the application side as I wanted to avoid having static values for the resolution and/or retrieving the resolution for every event (at least not till I've done some profiling). So I thought I would let you know anyways :)
I am dropping any plans on supporting CMake for this project. I have tried for the past week to get something building and it is far I have been unsuccessful. Working with CMake has been exceptionally painful for this project and the vague documentation is not doing me any favors. If you really want CMake support than please take a look at the cmake
branch and see if you can get it working. No integration will take place until Windows, Linux and OS X successfully build with CMake and I will not be wasting any more of my time trying to get it working as there are many other issues to address.
is this a paste error in libuiohook/src/darwin/post_event.c line 38 ? did you mean kCGEventFlagMaskCommand ?
Also on mac i had to comment out these lines at the end of the initialize_Modifiers function to make it work ( libuiohook/src/darwin/input_hook.c line 185):
// if (CGEventSourceFlagsState(kCGEventFlagMaskAlphaShift)) {
// set_modifier_mask(MASK_CAPS_LOCK);//ols: the hook doesn't start if this is called
// }
// Best I can tell, OS X does not support Num or Scroll lock.
//unset_modifier_mask(MASK_NUM_LOCK);
//unset_modifier_mask(MASK_SCROLL_LOCK); //ols: strange, but this sets both bits to 1
This lib is super useful. thanks for your work
I have two keyboards attaches to my Windows 7 computer.
Is it possible to know which keyboard sends the input when a keyboard event triggers.
I really need this function in my project.
Can anyone help me out with this.
Thanks a lot
When a keyboard event is handled a deadlock occurs on:
https://github.com/kwhat/libuiohook/blob/master/src/darwin/hook_callback.c#L221
I set up a small sample application in XCode to verify. Mouse events are handled well, but as soon as I hit any key on the keyboard the application doesn't output any further event logs any more.
Traced down to a deadlock in the handling procedure for keyboard events - possibly because a mutex is locked two times and never gets unlocked afterwards. When I pause the application in the debugger it shows a thread waiting at this line for the mutex to be unlocked.
I'm running a MacBook Air on OSX Maverix 10.9.3
Keep up the great work, I'm really glad I found this project :)
Thanks to the author for creating this library. I found a problem in the new apple system, which will block the system after my application has been running for some time.
Check the log only to find:
22:44:48.924282 +0800 kernel stalling for detach from IOHIDSystem
22:45:40.949872 +0800 kernel stalling for detach from IOHIDSystem
22:46:00.401860 +0800 kernel stalling for detach from IOHIDSystem
22:46:22.239122 +0800 kernel stalling for detach from IOHIDSystem
22:46:47.968963 +0800 kernel stalling for detach from IOHIDSystem
22:47:02.971121 +0800 kernel stalling for detach from IOHIDSystem
22:47:53.898890 +0800 kernel stalling for detach from IOHIDSystem
22:48:08.900830 +0800 kernel stalling for detach from IOHIDSystem
Every point of time is a pause. Can you help and give me any solution.
Hi @kwhat
I would like to use your library from a golang application. I have no knowledge of C so I have extracted the the compiled version of this library from the jnativehook.jar file. However, to use them I need the related header files and I don't which one to use. Could you please help me identifying the correct ones?
It's common practice to include a void*
argument in callback registers and then return it in the callback to allow the application to get back to their class or struct that should handle the callback. Without it, the application is forced to use global state to manage the callback, which is less nice to work with.
IMO this would be a nice thing to add whenever the API is next updated.
Before El Capitain (10.11) the property was:
defaults read com.apple.universalaccess mouseDriverMaxSpeed
(values range 1-32 (slow-fast)).
But now it is:
defaults read NSGlobalDomain com.apple.mouse.scaling
values appears to be between 0.0-3.0 (slow-fast)
Original:kwhat/jnativehook#110
Hi,
I don't actually have "real" issue with this (great!) lib, but rather a request if anyone has a simple working QT application with dynamic binding available?
I am unable to get it working with my QT app :-(
I "borrowed" the code from the example and only
// Set the logger callback for library output.
hook_set_logger_proc(&logger_proc);
// Set the event callback for uiohook events.
hook_set_dispatch_proc(&dispatch_proc);
do work, while the following
hook_run()
makes my program crash. The last log output I get is:
"%s [%u]: hInst was not set by DllMain().\n"
(with vars filled in, of course).
Anyone a hint for me?
Thanks a lot!
Error in demohook.exe:
refresh_locale_list [470]: GetKeyboardLayoutList(0, NULL) found 3 layouts.
refresh_locale_list [487]: Received 3 locales.
refresh_locale_list [628]: Could not find keyboard map for locale 0X00000000040A
0C0A!
refresh_locale_list [628]: Could not find keyboard map for locale 0X000000000409
0409!
refresh_locale_list [628]: Could not find keyboard map for locale 0XFFFFFFFFF029
1C01!
load_input_helper [860]: refresh_locale_list() found 0 locale(s).
id=4,when=197794244,mask=0x0,keycode=30,rawcode=0x41
refresh_locale_list [628]: Could not find keyboard map for locale 0X00000000040A
0C0A!
refresh_locale_list [628]: Could not find keyboard map for locale 0X000000000409
0409!
refresh_locale_list [628]: Could not find keyboard map for locale 0XFFFFFFFFF029
1C01!
id=5,when=197794354,mask=0x0,keycode=30,rawcode=0x41
id=5,when=0,mask=0x2,keycode=29,rawcode=0xA2
id=4,when=197803526,mask=0x0,keycode=30,rawcode=0x41
refresh_locale_list [628]: Could not find keyboard map for locale 0X00000000040A
0C0A!
refresh_locale_list [628]: Could not find keyboard map for locale 0X000000000409
0409!
refresh_locale_list [628]: Could not find keyboard map for locale 0XFFFFFFFFF029
1C01!
id=5,when=197803620,mask=0x0,keycode=30,rawcode=0x41
id=5,when=0,mask=0x202,keycode=29,rawcode=0xA2
How to reproduce error:
(Compiled in Windows 7 x64 with MSYS64 + MINGW64)
Mac media key events such as mute, volume up/down, play, etc are currently not detected.
However, there is way to do so:
http://weblog.rogueamoeba.com/2007/09/29/
http://overooped.com/post/2593597587/mediakeys
I'm not sure if master is supposed to be compilable, 1.0 seemed to have same issue?
This is the output of ./bootstrap ./configure and make
I have all the requirements and the OS is 14.04.02 LTS Ubuntu (I also tried on my local Arch Linux install but it had the same error) I'm able to get the branch you use for Jnativehook to compile.
All terminal output below:
./bootstrap.sh: 3: [: Linux: unexpected operator
autoreconf: Entering directory .' autoreconf: configure.ac: not using Gettext autoreconf: running: aclocal --force -I m4 autoreconf: configure.ac: tracing autoreconf: running: libtoolize --copy --force libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR,
config'.
libtoolize: copying file config/ltmain.sh' libtoolize: putting macros in AC_CONFIG_MACRO_DIR,
m4'.
libtoolize: copying file m4/libtool.m4' libtoolize: copying file
m4/ltoptions.m4'
libtoolize: copying file m4/ltsugar.m4' libtoolize: copying file
m4/ltversion.m4'
libtoolize: copying file m4/lt~obsolete.m4' autoreconf: running: /usr/bin/autoconf --force autoreconf: running: /usr/bin/autoheader --force autoreconf: running: automake --add-missing --copy --force-missing autoreconf: Leaving directory
.'
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking for style of include used by make... GNU
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether gcc understands -c and -o together... yes
checking dependency style of gcc... gcc3
checking for gcc option to accept ISO C99... -std=gnu99
checking for ar... ar
checking the archiver (ar) interface... ar
checking for an ANSI C-conforming const... yes
checking how to run the C preprocessor... gcc -std=gnu99 -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes
checking for stdint.h... (cached) yes
checking for uint64_t... yes
checking how to print strings... printf
checking for a sed that does not truncate output... /bin/sed
checking for fgrep... /bin/grep -F
checking for ld used by gcc -std=gnu99... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 1572864
checking whether the shell understands some XSI constructs... yes
checking whether the shell understands "+="... yes
checking how to convert x86_64-unknown-linux-gnu file names to x86_64-unknown-linux-gnu format... func_convert_file_noop
checking how to convert x86_64-unknown-linux-gnu file names to toolchain format... func_convert_file_noop
checking for /usr/bin/ld option to reload object files... -r
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for archiver @file support... @
checking for strip... strip
checking for ranlib... ranlib
checking command to parse /usr/bin/nm -B output from gcc -std=gnu99 object... ok
checking for sysroot... no
checking for mt... mt
checking if mt is a manifest tool... no
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc -std=gnu99 supports -fno-rtti -fno-exceptions... no
checking for gcc -std=gnu99 option to produce PIC... -fPIC -DPIC
checking if gcc -std=gnu99 PIC flag -fPIC -DPIC works... yes
checking if gcc -std=gnu99 static flag -static works... yes
checking if gcc -std=gnu99 supports -c -o file.o... yes
checking if gcc -std=gnu99 supports -c -o file.o... (cached) yes
checking whether the gcc -std=gnu99 linker (/usr/bin/ld -m elf_x86_64) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... GNU/Linux ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking operating system... x86_64-unknown-linux-gnu (Linux Compatible)
checking for pkg-config... /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for X11... yes
checking for XTST... yes
checking for XRecordQueryVersion in -lXtst... yes
checking for X11/extensions/record.h... yes
checking for XT... yes
checking for XTestQueryExtension in -lXtst... yes
checking for X11/extensions/XTest.h... yes
checking for XINERAMA... yes
checking that generated files are newer than configure... done
configure: creating ./config.status
config.status: creating pc/uiohook.pc
config.status: creating Makefile
config.status: creating include/config.h
config.status: include/config.h is unchanged
config.status: executing depfiles commands
config.status: executing libtool commands
/bin/bash ./libtool --tag=CC --mode=link gcc -std=gnu99 -Wall -Wextra -pedantic -Wno-unused-parameter -I./include -I./src/x11 -I./src -g -O2 -Wl,--no-undefined -Wl,--no-undefined -o libuiohook.la -rpath /usr/local/lib src/libuiohook_la-logger.lo src/x11/libuiohook_la-input_helper.lo src/x11/libuiohook_la-input_hook.lo src/x11/libuiohook_la-post_event.lo src/x11/libuiohook_la-system_properties.lo -lXinerama -lXt -lX11 -lXtst -lXtst -lX11
libtool: link: gcc -std=gnu99 -shared -fPIC -DPIC src/.libs/libuiohook_la-logger.o src/x11/.libs/libuiohook_la-input_helper.o src/x11/.libs/libuiohook_la-input_hook.o src/x11/.libs/libuiohook_la-post_event.o src/x11/.libs/libuiohook_la-system_properties.o -lXinerama -lXt -lXtst -lX11 -O2 -Wl,--no-undefined -Wl,--no-undefined -Wl,-soname -Wl,libuiohook.so.0 -o .libs/libuiohook.so.0.0.0
src/x11/.libs/libuiohook_la-input_hook.o: In function hook_event_proc': /home/brad/Downloads/libuiohook-master/src/x11/input_hook.c:589: undefined reference to
hook_get_screen_info'
collect2: error: ld returned 1 exit status
make: *** [libuiohook.la] Error 1
In Mac 10.9.4 I'm seeing for every key event the message:
Failed to signal RunLoop main!
Due to CFRunLoopCopyCurrentMode returning NULL, which from the docs means that the main loop is not running although at least CFRunLoopRun is blocking on the other thread.
CFStringRef mode = CFRunLoopCopyCurrentMode(CFRunLoopGetMain());
CFRunLoopGetMain() -> 0x7f8d3ca00100, mode 0x0
CFRunLoopCopyCurrentMode(CFRunLoopGetMain()) -> mode 0x0
This is just affecting the key typed detection but it is annoying nevertheless ;)
Since hook_run
blocks the thread until stop is called, the only places hook_stop
can be called on the same thread are in callbacks, which is what the two demos do. If an application wants to to stop hook on demand though, relying on user input to cause a callback while trying to shutdown seems unreliable.
Alternatively calling hook_stop
from an outside thread looks unsafe since hooks API are not thread safe. This might not be that bad in practice since hook_run
looks like it will be blocked on other library calls and not accessing its structure data after startup, but this still doesn't give any guarantees of thread safety.
A possible workaround might be to stop from the callback and inject an event from the application to force a callback, but this seems pretty convoluted.
I think the API would be easier to work with if hook_run
was called periodically from the application and returned, instead of being called once and blocking, allowing the application to call other API in between checking for new keys.
I am using the 1.1 branch, build fails on MacOS 10.15
error: too many arguments to function call, expected 0, have 3
on this line (and others)
I ran the following commands:
./bootstrap.sh
./configure
make
Looks like event EVENT_KEY_TYPED never fires in macOS Sierra 10.12.
I try my project on Ubuntu 16.04 works fine but in macOS this event never fires,
but EVENT_KEY_PRESSED and EVENT_KEY_RELEASED working great
I can't find way to prevent event. Can libuiohook do it?
Will be cool prevent event after receiving (optionally)
Not really a bug, but someone's using my obs-studio plugin, which loads libuiohook together with another piece of software that also uses the library (restream chat) and it causes the mouse input to slow down to a crawl.
The restream program is a node app, which doesn't have public source, but I just assume they used this version of libuiohook.
I've seen the behavior when launching two instances of the async demo. Just wondering if there's anything that I can do on my side to prevent this from happening or if there's no way to have two instances of the hook running in parallel.
When issuing the "make && make install" as described, it throws the following error:
src/x11/.libs/libuiohook_la-input_hook.o: In function `hook_event_proc':
./libuiohook/src/x11/input_hook.c:589: undefined reference to `hook_get_screen_info'
collect2: error: ld returned 1 exit status
Makefile:686: recipe for target 'libuiohook.la' failed
make: *** [libuiohook.la] Error 1
maybe function name changed ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.