<commit_before>// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// https://github.com/go-vgo/robotgo/blob/master/LICENSE
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#ifdef HAVE_CONFIG_H
	#include <config.h>
#endif

#include "../base/os.h"

#if defined(IS_MACOSX)
	#include "hook/darwin/input_c.h"
	#include "hook/darwin/hook_c.h"
	#include "hook/darwin/event_c.h"
	#include "hook/darwin/properties_c.h"
#elif defined(USE_X11)
	//#define USE_XKBCOMMON 0
	#include "hook/x11/input_c.h"
	#include "hook/x11/hook_c.h"
	#include "hook/x11/event_c.h"
	#include "hook/x11/properties_c.h"
#elif defined(IS_WINDOWS)
	#include "hook/windows/input_c.h"
	#include "hook/windows/hook_c.h"
	#include "hook/windows/event_c.h"
	#include "hook/windows/properties_c.h"
#endif

#include <inttypes.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "hook/iohook.h"

int aStop();
int aEvent(char *aevent);

bool logger_proc(unsigned int level, const char *format, ...) {
	bool status = false;

	va_list args;
	switch (level) {
		#ifdef USE_DEBUG
		case LOG_LEVEL_DEBUG:
		case LOG_LEVEL_INFO:
			va_start(args, format);
			status = vfprintf(stdout, format, args) >= 0;
			va_end(args);
			break;
		#endif

		case LOG_LEVEL_WARN:
		case LOG_LEVEL_ERROR:
			va_start(args, format);
			status = vfprintf(stderr, format, args) >= 0;
			va_end(args);
			break;
	}

	return status;
}

// NOTE: The following callback executes on the same thread that hook_run() is called
// from.

struct _MEvent {
	uint8_t id;
	size_t mask;
	uint16_t keychar;
	// char *keychar;
	size_t x;
	uint8_t y;
	uint8_t bytesPerPixel;
};

typedef struct _MEvent MEvent;
// typedef MMBitmap *MMBitmapRef;
char *cevent;
// uint16_t *cevent;
int cstatus=1;

MEvent mEvent;
void dispatch_proc(iohook_event * const event) {
	char buffer[256] = { 0 };
	size_t length = snprintf(buffer, sizeof(buffer),
			"id=%i,when=%" PRIu64 ",mask=0x%X",
			event->type, event->time, event->mask);

	switch (event->type) {
		case EVENT_KEY_PRESSED:
			// If the escape key is pressed, naturally terminate the program.
			if (event->data.keyboard.keycode == VC_ESCAPE) {
				int status = hook_stop();
				switch (status) {
					// System level errors.
					case IOHOOK_ERROR_OUT_OF_MEMORY:
						logger_proc(LOG_LEVEL_ERROR, "Failed to allocate memory. (%#X)", status);
						break;

					case IOHOOK_ERROR_X_RECORD_GET_CONTEXT:
						// NOTE This is the only platform specific error that occurs on hook_stop().
						logger_proc(LOG_LEVEL_ERROR, "Failed to get XRecord context. (%#X)", status);
						break;

					// Default error.
					case IOHOOK_FAILURE:
					default:
						logger_proc(LOG_LEVEL_ERROR, "An unknown hook error occurred. (%#X)", status);
						break;
				}
			}
		case EVENT_KEY_RELEASED:
			snprintf(buffer + length, sizeof(buffer) - length,
				",keycode=%u,rawcode=0x%X",
				event->data.keyboard.keycode, event->data.keyboard.rawcode);
			break;

		case EVENT_KEY_TYPED:
			snprintf(buffer + length, sizeof(buffer) - length,
				",keychar=%lc,rawcode=%u",
				(uint16_t) event->data.keyboard.keychar,//wint_t
				event->data.keyboard.rawcode);
				
				#ifdef  WE_REALLY_WANT_A_POINTER
					char *buf = malloc (6);
				#else
					char buf[6];
				#endif

					sprintf(buf, "%lc",(uint16_t) event->data.keyboard.keychar);

				#ifdef WE_REALLY_WANT_A_POINTER
					free (buf);
				#endif

				if (strcmp(buf, cevent) == 0){
					int astop=aStop();
					// printf("%d\n",astop);
					cstatus=0;
				}
				// return (char*) event->data.keyboard.keychar;
			break;

		case EVENT_MOUSE_PRESSED:
		case EVENT_MOUSE_RELEASED:
		case EVENT_MOUSE_CLICKED:
		case EVENT_MOUSE_MOVED:
		case EVENT_MOUSE_DRAGGED:
			snprintf(buffer + length, sizeof(buffer) - length,
				",x=%i,y=%i,button=%i,clicks=%i",
				event->data.mouse.x, event->data.mouse.y,
				event->data.mouse.button, event->data.mouse.clicks);
				int abutton=event->data.mouse.button;
				int aclicks=event->data.mouse.clicks;
				int amouse;
				if (strcmp(cevent,"mleft") == 0){
					amouse=1;
				}
				if (strcmp(cevent,"mright") == 0){
					amouse=2;
				}
				if (strcmp(cevent,"wheelDown") == 0){
					amouse=4;
				}<commit_msg>Fix mouse null<commit_after>// Copyright 2016 The go-vgo Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// https://github.com/go-vgo/robotgo/blob/master/LICENSE
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#ifdef HAVE_CONFIG_H
	#include <config.h>
#endif

#include "../base/os.h"

#if defined(IS_MACOSX)
	#include "hook/darwin/input_c.h"
	#include "hook/darwin/hook_c.h"
	#include "hook/darwin/event_c.h"
	#include "hook/darwin/properties_c.h"
#elif defined(USE_X11)
	//#define USE_XKBCOMMON 0
	#include "hook/x11/input_c.h"
	#include "hook/x11/hook_c.h"
	#include "hook/x11/event_c.h"
	#include "hook/x11/properties_c.h"
#elif defined(IS_WINDOWS)
	#include "hook/windows/input_c.h"
	#include "hook/windows/hook_c.h"
	#include "hook/windows/event_c.h"
	#include "hook/windows/properties_c.h"
#endif

#include <inttypes.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "hook/iohook.h"

int aStop();
int aEvent(char *aevent);

bool logger_proc(unsigned int level, const char *format, ...) {
	bool status = false;

	va_list args;
	switch (level) {
		#ifdef USE_DEBUG
		case LOG_LEVEL_DEBUG:
		case LOG_LEVEL_INFO:
			va_start(args, format);
			status = vfprintf(stdout, format, args) >= 0;
			va_end(args);
			break;
		#endif

		case LOG_LEVEL_WARN:
		case LOG_LEVEL_ERROR:
			va_start(args, format);
			status = vfprintf(stderr, format, args) >= 0;
			va_end(args);
			break;
	}

	return status;
}

// NOTE: The following callback executes on the same thread that hook_run() is called
// from.

struct _MEvent {
	uint8_t id;
	size_t mask;
	uint16_t keychar;
	// char *keychar;
	size_t x;
	uint8_t y;
	uint8_t bytesPerPixel;
};

typedef struct _MEvent MEvent;
// typedef MMBitmap *MMBitmapRef;
char *cevent;
// uint16_t *cevent;
int cstatus=1;

MEvent mEvent;
void dispatch_proc(iohook_event * const event) {
	char buffer[256] = { 0 };
	size_t length = snprintf(buffer, sizeof(buffer),
			"id=%i,when=%" PRIu64 ",mask=0x%X",
			event->type, event->time, event->mask);

	switch (event->type) {
		case EVENT_KEY_PRESSED:
			// If the escape key is pressed, naturally terminate the program.
			if (event->data.keyboard.keycode == VC_ESCAPE) {
				int status = hook_stop();
				switch (status) {
					// System level errors.
					case IOHOOK_ERROR_OUT_OF_MEMORY:
						logger_proc(LOG_LEVEL_ERROR, "Failed to allocate memory. (%#X)", status);
						break;

					case IOHOOK_ERROR_X_RECORD_GET_CONTEXT:
						// NOTE This is the only platform specific error that occurs on hook_stop().
						logger_proc(LOG_LEVEL_ERROR, "Failed to get XRecord context. (%#X)", status);
						break;

					// Default error.
					case IOHOOK_FAILURE:
					default:
						logger_proc(LOG_LEVEL_ERROR, "An unknown hook error occurred. (%#X)", status);
						break;
				}
			}
		case EVENT_KEY_RELEASED:
			snprintf(buffer + length, sizeof(buffer) - length,
				",keycode=%u,rawcode=0x%X",
				event->data.keyboard.keycode, event->data.keyboard.rawcode);
			break;

		case EVENT_KEY_TYPED:
			snprintf(buffer + length, sizeof(buffer) - length,
				",keychar=%lc,rawcode=%u",
				(uint16_t) event->data.keyboard.keychar,//wint_t
				event->data.keyboard.rawcode);
				
				#ifdef  WE_REALLY_WANT_A_POINTER
					char *buf = malloc (6);
				#else
					char buf[6];
				#endif

					sprintf(buf, "%lc",(uint16_t) event->data.keyboard.keychar);

				#ifdef WE_REALLY_WANT_A_POINTER
					free (buf);
				#endif

				if (strcmp(buf, cevent) == 0){
					int astop=aStop();
					// printf("%d\n",astop);
					cstatus=0;
				}
				// return (char*) event->data.keyboard.keychar;
			break;

		case EVENT_MOUSE_PRESSED:
		case EVENT_MOUSE_RELEASED:
		case EVENT_MOUSE_CLICKED:
		case EVENT_MOUSE_MOVED:
		case EVENT_MOUSE_DRAGGED:
			snprintf(buffer + length, sizeof(buffer) - length,
				",x=%i,y=%i,button=%i,clicks=%i",
				event->data.mouse.x, event->data.mouse.y,
				event->data.mouse.button, event->data.mouse.clicks);
				int abutton=event->data.mouse.button;
				int aclicks=event->data.mouse.clicks;
				int amouse=0;
				if (strcmp(cevent,"mleft") == 0){
					amouse=1;
				}
				if (strcmp(cevent,"mright") == 0){
					amouse=2;
				}
				if (strcmp(cevent,"wheelDown") == 0){
					amouse=4;
				}
{'fraction_non_alphanumeric': 0.1398562741846324, 'fraction_numerical': 0.011387506909894969, 'mean_word_length': 3.5617750882501262, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 57, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7508302', 'n_tokens_mistral': 3903, 'n_tokens_neox': 3367, 'n_words': 760}