kern_return_t IOHIDGetMouseButtonMode( io_connect_t handle, int * mode ) { IOByteCount rsize; return( IOHIDGetParameter( handle, CFSTR(kIOHIDPointerButtonMode), sizeof( *mode), (unsigned char *) mode, &rsize )); }
// Key repeat delay helper (result in ns) long repeattime(io_connect_t event, int first){ long delay = 0; IOByteCount actualSize = 0; if(IOHIDGetParameter(event, first ? CFSTR(kIOHIDInitialKeyRepeatKey) : CFSTR(kIOHIDKeyRepeatKey), sizeof(long), &delay, &actualSize) != KERN_SUCCESS || actualSize == 0) return -1; return delay; }
double NXClickTime(NXEventHandle handle) { UInt64 params; IOByteCount rcnt = EVSIOCCT_SIZE; int r; r = IOHIDGetParameter(handle, CFSTR(EVSIOCCT), sizeof(UInt64), ¶ms, &rcnt ); if ( r != kIOReturnSuccess ) return 0.0; return packed_nsecs_to_secs( params ); }
double NXKeyRepeatThreshold(NXEventHandle handle) { UInt64 params; IOByteCount rcnt = EVSIOCKR_SIZE; int r; r = IOHIDGetParameter( handle, CFSTR(EVSIOSIKR), sizeof(UInt64), ¶ms, &rcnt ); if ( r != kIOReturnSuccess ) return 0.0; return packed_nsecs_to_secs( params ); }
kern_return_t IOHIDGetAccelerationWithKey( io_connect_t handle, CFStringRef key, double * acceleration ) { kern_return_t kr; unsigned int fixed; IOByteCount rsize; kr = IOHIDGetParameter( handle, key, sizeof( fixed), (unsigned char *) &fixed, &rsize ); if( kr == kIOReturnSuccess) *acceleration = ((double) fixed) / 65536.0; return( kr ); }
kern_return_t IOHIDGetMouseAcceleration( io_connect_t handle, double * acceleration ) { kern_return_t kr; unsigned int fixed; IOByteCount rsize; kr = IOHIDGetParameter( handle, CFSTR(kIOHIDPointerAccelerationKey), sizeof( fixed), (unsigned char *) &fixed, &rsize ); if( kr == kIOReturnSuccess) *acceleration = ((double) fixed) / 65536.0; return( kr ); }
UIOHOOK_API long int hook_get_auto_repeat_rate() { #if defined USE_IOKIT || defined USE_COREFOUNDATION || defined USE_CARBON_LEGACY bool successful = false; SInt64 rate; #endif long int value = -1; #ifdef USE_IOKIT if (!successful) { io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching(kIOHIDSystemClass)); if (service) { kern_return_t kren_ret = kIOReturnError; io_connect_t connection; kren_ret = IOServiceOpen(service, mach_task_self(), kIOHIDParamConnectType, &connection); if (kren_ret == kIOReturnSuccess) { IOByteCount size = sizeof(rate); kren_ret = IOHIDGetParameter(connection, CFSTR(kIOHIDKeyRepeatKey), (IOByteCount) sizeof(rate), &rate, &size); if (kren_ret == kIOReturnSuccess) { /* This is in some undefined unit of time that if we happen * to multiply by 900 gives us the time in milliseconds. We * add 0.5 to the result so that when we cast to long we * actually get a rounded result. Saves the math.h depend. * * 33,333,333.0 / 1000.0 / 1000.0 / 1000.0 == 0.033333333 * Fast * * 100,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 0.1 * 200,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 0.2 * 500,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 0.5 * 1,000,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 1 * 1,500,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 1.5 * 2,000,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 2 * Slow * */ value = (long) (900.0 * ((double) rate) / 1000.0 / 1000.0 / 1000.0 + 0.5); successful = true; logger(LOG_LEVEL_INFO, "%s [%u]: IOHIDGetParameter: %li.\n", __FUNCTION__, __LINE__, value); } } } } #endif #ifdef USE_COREFOUNDATION if (!successful) { CFTypeRef pref_val = CFPreferencesCopyValue(CFSTR("KeyRepeat"), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost); if (pref_val != NULL && CFGetTypeID(pref_val) == CFNumberGetTypeID()) { if (CFNumberGetValue((CFNumberRef) pref_val, kCFNumberSInt32Type, &rate)) { // This is the slider value, we must multiply by 15 to convert to milliseconds. value = (long) rate * 15; successful = true; logger(LOG_LEVEL_INFO, "%s [%u]: CFPreferencesCopyValue: %li.\n", __FUNCTION__, __LINE__, value); } } } #endif #ifdef USE_CARBON_LEGACY if (!successful) { // Apple documentation states that value is in 'ticks'. I am not sure // what that means, but it looks a lot like the arbitrary slider value. rate = LMGetKeyRepThresh(); if (rate > -1) { /* This is the slider value, we must multiply by 15 to convert to * milliseconds. */ value = (long) rate * 15; successful = true; logger(LOG_LEVEL_INFO, "%s [%u]: LMGetKeyRepThresh: %li.\n", __FUNCTION__, __LINE__, value); } } #endif return value; }
UIOHOOK_API long int hook_get_multi_click_time() { #if defined USE_IOKIT || defined USE_COREFOUNDATION || defined USE_CARBON_LEGACY bool successful = false; #if defined USE_IOKIT || defined USE_CARBON_LEGACY // This needs to be defined only if we have USE_IOKIT or USE_CARBON_LEGACY. SInt64 time; #endif #endif long int value = -1; #ifdef USE_IOKIT if (!successful) { io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching(kIOHIDSystemClass)); if (service) { kern_return_t kren_ret = kIOReturnError; io_connect_t connection; kren_ret = IOServiceOpen(service, mach_task_self(), kIOHIDParamConnectType, &connection); if (kren_ret == kIOReturnSuccess) { IOByteCount size = sizeof(time); kren_ret = IOHIDGetParameter(connection, CFSTR(kIOHIDClickTimeKey), (IOByteCount) sizeof(time), &time, &size); if (kren_ret == kIOReturnSuccess) { /* This is in some undefined unit of time that if we happen * to multiply by 900 gives us the time in milliseconds. We * add 0.5 to the result so that when we cast to long we * actually get a rounded result. Saves the math.h depend. */ value = (long) (900.0 * ((double) time) / 1000.0 / 1000.0 / 1000.0 + 0.5); successful = true; logger(LOG_LEVEL_INFO, "%s [%u]: IOHIDGetParameter: %li.\n", __FUNCTION__, __LINE__, value); } } } } #endif #ifdef USE_COREFOUNDATION if (!successful) { Float32 clicktime; CFTypeRef pref_val = CFPreferencesCopyValue(CFSTR("com.apple.mouse.doubleClickThreshold"), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost); if (pref_val != NULL && CFGetTypeID(pref_val) == CFNumberGetTypeID()) { if (CFNumberGetValue((CFNumberRef) pref_val, kCFNumberFloat32Type, &clicktime)) { /* This is in some undefined unit of time that if we happen * to multiply by 900 gives us the time in milliseconds. It is * completely possible that this value is in seconds and should be * multiplied by 1000 but because IOKit values are undocumented and * I have no idea what a Carbon 'tick' is so there really is no way * to confirm this. */ value = (long) (clicktime * 900); logger(LOG_LEVEL_INFO, "%s [%u]: CFPreferencesCopyValue: %li.\n", __FUNCTION__, __LINE__, value); } } } #endif #ifdef USE_CARBON_LEGACY if (!successful) { // Apple documentation states that value is in 'ticks'. I am not sure // what that means, but it looks a lot like the arbitrary slider value. time = GetDblTime(); if (time > -1) { // This is the slider value, we must multiply by 15 to convert to // milliseconds. value = (long) time * 15; successful = true; logger(LOG_LEVEL_INFO, "%s [%u]: GetDblTime: %li.\n", __FUNCTION__, __LINE__, value); } } #endif return value; }
long int GetAutoRepeatDelay() { #if defined IOKIT || defined COREFOUNDATION || defined CARBON_LEGACY bool successful = false; SInt64 delay; #endif long int value = -1; #ifdef IOKIT if (!successful) { io_service_t service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching(kIOHIDSystemClass)); if (service) { kern_return_t kren_ret = kIOReturnError; io_connect_t connection; kren_ret = IOServiceOpen(service, mach_task_self(), kIOHIDParamConnectType, &connection); if (kren_ret == kIOReturnSuccess) { IOByteCount size = sizeof(delay); kren_ret = IOHIDGetParameter(connection, CFSTR(kIOHIDInitialKeyRepeatKey), (IOByteCount) sizeof(delay), &delay, &size); if (kren_ret == kIOReturnSuccess) { /* This is in some undefined unit of time that if we happen * to multiply by 900 gives us the time in milliseconds. We * add 0.5 to the result so that when we cast to long we * actually get a rounded result. Saves the math.h depend. * * 33,333,333.0 / 1000.0 / 1000.0 / 1000.0 == 0.033333333 * Fast * * 100,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 0.1 * 200,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 0.2 * 500,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 0.5 * 1,000,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 1 * 1,500,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 1.5 * 2,000,000,000.0 / 1000.0 / 1000.0 / 1000.0 == 2 * Slow * */ value = (long) (900.0 * ((double) delay) / 1000.0 / 1000.0 / 1000.0 + 0.5); successful = true; } } } } #endif #ifdef COREFOUNDATION if (!successful) { CFTypeRef pref_val = CFPreferencesCopyValue(CFSTR("InitialKeyRepeat"), kCFPreferencesAnyApplication, kCFPreferencesCurrentUser, kCFPreferencesAnyHost); if (pref_val != NULL && CFGetTypeID(pref_val) == CFNumberGetTypeID()) { if (CFNumberGetValue((CFNumberRef) pref_val, kCFNumberSInt32Type, &delay)) { // This is the slider value, we must multiply by 15 to convert to // milliseconds. printf("Test: %i\n\n", (int) delay); value = (long) delay * 15; successful = true; } } } #endif #ifdef CARBON_LEGACY if (!successful) { // Apple documentation states that value is in 'ticks'. I am not sure // what that means, but it looks a lot like the arbitrary slider value. delay = LMGetKeyThresh(); if (delay > -1) { // This is the slider value, we must multiply by 15 to convert to // milliseconds. value = (long) delay * 15; successful = true; } } #endif return value; }