with comments for if stucts are needed later
This commit is contained in:
parent
be3453c37d
commit
79e3e153bd
@ -9,14 +9,14 @@ static int DIRTY = 0;
|
|||||||
struct linked_list
|
struct linked_list
|
||||||
{
|
{
|
||||||
unsigned long number;
|
unsigned long number;
|
||||||
int keycode;
|
KeyCode keycode;
|
||||||
struct linked_list *next;
|
struct linked_list *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct linked_list node;
|
typedef struct linked_list node;
|
||||||
node *head=NULL, *last=NULL;
|
node *head = NULL, *last = NULL;
|
||||||
|
|
||||||
void insertAtLast(unsigned long value, int keycode) {
|
void insertAtLast(unsigned long value, KeyCode keycode) {
|
||||||
node *temp_node;
|
node *temp_node;
|
||||||
temp_node = (node *) malloc(sizeof(node));
|
temp_node = (node *) malloc(sizeof(node));
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ void insertAtLast(unsigned long value, int keycode) {
|
|||||||
temp_node->next = NULL;
|
temp_node->next = NULL;
|
||||||
|
|
||||||
//For the 1st element
|
//For the 1st element
|
||||||
if(head == NULL) {
|
if(!head) {
|
||||||
head = temp_node;
|
head = temp_node;
|
||||||
last = temp_node;
|
last = temp_node;
|
||||||
} else {
|
} else {
|
||||||
@ -34,17 +34,17 @@ void insertAtLast(unsigned long value, int keycode) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteItem(int value) {
|
void deleteItem(unsigned long value) {
|
||||||
node *myNode = head, *previous=NULL;
|
node *myNode = head, *previous = NULL;
|
||||||
|
|
||||||
while(myNode!=NULL) {
|
while(myNode) {
|
||||||
if(myNode->number==value) {
|
if(myNode->number == value) {
|
||||||
if(previous==NULL)
|
if(!previous)
|
||||||
head = myNode->next;
|
head = myNode->next;
|
||||||
else
|
else
|
||||||
previous->next = myNode->next;
|
previous->next = myNode->next;
|
||||||
|
|
||||||
free(myNode); //need to free up the memory to prevent memory leak
|
free(myNode);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,20 +53,18 @@ void deleteItem(int value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int searchItem(int value) {
|
node *searchItemNode(unsigned long value) {
|
||||||
node *searchNode = head;
|
node *searchNode = head;
|
||||||
int flag = 0;
|
|
||||||
|
|
||||||
while(searchNode != NULL) {
|
while(searchNode) {
|
||||||
if(searchNode->number==value) {
|
if(searchNode->number == value) {
|
||||||
flag = searchNode->keycode;
|
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
searchNode = searchNode->next;
|
searchNode = searchNode->next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return flag;
|
return searchNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
Display *getXDisplay(void) {
|
Display *getXDisplay(void) {
|
||||||
@ -189,41 +187,58 @@ KeyCode XkbKeysymToKeycode(KeySym keysym) {
|
|||||||
return keycode;
|
return keycode;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XKey(unsigned long key, int down) {
|
int XKey(unsigned long key, int down) {
|
||||||
if (key != 0) {
|
Display *display = getXDisplay();
|
||||||
Display *display = getXDisplay();
|
KeyCode code = -2;
|
||||||
// KeyCode code = XKeysymToKeycode(display, key);
|
// node *compareNode;
|
||||||
|
// compareNode = searchItemNode(key);
|
||||||
|
|
||||||
int code;
|
if (down) {
|
||||||
|
// if (compareNode && compareNode != last) {
|
||||||
|
// code = compareNode->keycode;
|
||||||
|
// } else {
|
||||||
|
code = XkbKeysymToKeycode(key);
|
||||||
|
if (!code) {
|
||||||
|
int min, max, numcodes;
|
||||||
|
XDisplayKeycodes(display, &min, &max);
|
||||||
|
XGetKeyboardMapping(display, min, max-min, &numcodes);
|
||||||
|
|
||||||
if (down) {
|
code = (max-min+1)*numcodes;
|
||||||
code = searchItem(key);
|
KeySym keysym_list[numcodes];
|
||||||
if (code == 0) {
|
for(int i=0;i<numcodes;i++) keysym_list[i] = key;
|
||||||
// XKeysymToKeycode() doesn't respect state, so we have to use
|
XChangeKeyboardMapping(display, code, numcodes, keysym_list, 1);
|
||||||
// something slightly more complex
|
|
||||||
code = XkbKeysymToKeycode(key);
|
|
||||||
// Map non-existing keysyms to new keycodes
|
|
||||||
if(code == 0) {
|
|
||||||
int min, max, numcodes;
|
|
||||||
XDisplayKeycodes(display, &min, &max);
|
|
||||||
XGetKeyboardMapping(display, min, max-min, &numcodes);
|
|
||||||
|
|
||||||
code = (max-min+1)*numcodes;
|
|
||||||
KeySym keysym_list[numcodes];
|
|
||||||
for(int i=0;i<numcodes;i++) keysym_list[i] = key;
|
|
||||||
XChangeKeyboardMapping(display, code, numcodes, keysym_list, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
insertAtLast(key, code);
|
|
||||||
}
|
}
|
||||||
} else {
|
if (!code)
|
||||||
code = searchItem(key);
|
return -1;
|
||||||
deleteItem(key);
|
// }
|
||||||
}
|
// insertAtLast(key, code);
|
||||||
|
|
||||||
XTestFakeKeyEvent(display, code, down, CurrentTime);
|
XTestFakeKeyEvent(display, code, down, CurrentTime);
|
||||||
XSync(display, 0);
|
XSync(display, 0);
|
||||||
|
} else {
|
||||||
|
// if (compareNode) {
|
||||||
|
// code = compareNode->keycode;
|
||||||
|
|
||||||
|
code = XkbKeysymToKeycode(key);
|
||||||
|
if (!code) {
|
||||||
|
int min, max, numcodes;
|
||||||
|
XDisplayKeycodes(display, &min, &max);
|
||||||
|
XGetKeyboardMapping(display, min, max-min, &numcodes);
|
||||||
|
|
||||||
|
code = (max-min+1)*numcodes;
|
||||||
|
KeySym keysym_list[numcodes];
|
||||||
|
for(int i=0;i<numcodes;i++) keysym_list[i] = key;
|
||||||
|
XChangeKeyboardMapping(display, code, numcodes, keysym_list, 1);
|
||||||
|
}
|
||||||
|
if (!code)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
XTestFakeKeyEvent(display, code, down, CurrentTime);
|
||||||
|
XSync(display, 0);
|
||||||
|
// deleteItem(key);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
void XClipboardSet(char *src) {
|
void XClipboardSet(char *src) {
|
||||||
|
@ -73,9 +73,12 @@ func KeyDown(code uint64) error {
|
|||||||
return fmt.Errorf("debounced key %v", code)
|
return fmt.Errorf("debounced key %v", code)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Code-Press %v", code)
|
||||||
debounce_key[code] = time.Now()
|
debounce_key[code] = time.Now()
|
||||||
|
|
||||||
C.XKey(C.ulong(code), C.int(1))
|
t := C.XKey(C.ulong(code), C.int(1))
|
||||||
|
|
||||||
|
fmt.Printf("X-Press %v", t)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +106,10 @@ func KeyUp(code uint64) error {
|
|||||||
|
|
||||||
delete(debounce_key, code)
|
delete(debounce_key, code)
|
||||||
|
|
||||||
C.XKey(C.ulong(code), C.int(0))
|
fmt.Printf("Code-Release %v", code)
|
||||||
|
t := C.XKey(C.ulong(code), C.int(0))
|
||||||
|
|
||||||
|
fmt.Printf("X-Release %v", t)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
void XMove(int x, int y);
|
void XMove(int x, int y);
|
||||||
void XScroll(int x, int y);
|
void XScroll(int x, int y);
|
||||||
void XButton(unsigned int button, int down);
|
void XButton(unsigned int button, int down);
|
||||||
void XKey(unsigned long key, int down);
|
int XKey(unsigned long key, int down);
|
||||||
|
|
||||||
void XClipboardSet(char *src);
|
void XClipboardSet(char *src);
|
||||||
char *XClipboardGet();
|
char *XClipboardGet();
|
||||||
|
Reference in New Issue
Block a user