Archived
1
0

Adding support for relative movement mouse keys

- Includes kll.py cleanup
- Fixed negative number generation and parsing
This commit is contained in:
Jacob Alexander 2016-03-21 22:22:13 -07:00
parent 55ffc6bdc5
commit d3e0c3d7a7
2 changed files with 73 additions and 48 deletions

36
kll.py
View File

@ -1,8 +1,10 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# KLL Compiler '''
# Keyboard Layout Langauge KLL Compiler
# Keyboard Layout Langauge
# Copyright (C) 2014-2015 by Jacob Alexander '''
# Copyright (C) 2014-2016 by Jacob Alexander
# #
# This file is free software: you can redistribute it and/or modify # This file is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -21,21 +23,16 @@
import argparse import argparse
import importlib import importlib
import io
import os import os
import re
import sys import sys
import token
from pprint import pformat
from re import VERBOSE from re import VERBOSE
from tokenize import generate_tokens
from kll_lib.containers import * from kll_lib.containers import *
from kll_lib.hid_dict import * from kll_lib.hid_dict import *
from funcparserlib.lexer import make_tokenizer, Token, LexerError from funcparserlib.lexer import make_tokenizer, Token, LexerError
from funcparserlib.parser import (some, a, many, oneplus, skip, finished, maybe, skip, forward_decl, NoParseError) from funcparserlib.parser import (some, a, many, oneplus, finished, maybe, skip, NoParseError)
@ -150,12 +147,12 @@ def tokenize( string ):
( 'String', ( r'"[^"]*"', ) ), ( 'String', ( r'"[^"]*"', ) ),
( 'SequenceString', ( r"'[^']*'", ) ), ( 'SequenceString', ( r"'[^']*'", ) ),
( 'Operator', ( r'=>|:\+|:-|::|:|=', ) ), ( 'Operator', ( r'=>|:\+|:-|::|:|=', ) ),
( 'Number', ( r'(-[ \t]*)?((0x[0-9a-fA-F]+)|(0|([1-9][0-9]*)))', VERBOSE ) ),
( 'Comma', ( r',', ) ), ( 'Comma', ( r',', ) ),
( 'Dash', ( r'-', ) ), ( 'Dash', ( r'-', ) ),
( 'Plus', ( r'\+', ) ), ( 'Plus', ( r'\+', ) ),
( 'Parenthesis', ( r'\(|\)', ) ), ( 'Parenthesis', ( r'\(|\)', ) ),
( 'None', ( r'None', ) ), ( 'None', ( r'None', ) ),
( 'Number', ( r'-?(0x[0-9a-fA-F]+)|(0|([1-9][0-9]*))', VERBOSE ) ),
( 'Name', ( r'[A-Za-z_][A-Za-z_0-9]*', ) ), ( 'Name', ( r'[A-Za-z_][A-Za-z_0-9]*', ) ),
( 'VariableContents', ( r'''[^"' ;:=>()]+''', ) ), ( 'VariableContents', ( r'''[^"' ;:=>()]+''', ) ),
( 'EndOfLine', ( r';', ) ), ( 'EndOfLine', ( r';', ) ),
@ -398,14 +395,27 @@ def oneLayerFlatten( items ):
return mainList return mainList
# Capability arguments may need to be expanded (e.g. 1 16 bit argument needs to be 2 8 bit arguments for the state machine)
def capArgExpander( items ): def capArgExpander( items ):
'''
Capability arguments may need to be expanded
(e.g. 1 16 bit argument needs to be 2 8 bit arguments for the state machine)
If the number is negative, determine width of the final value, mask to max, subtract,
then convert to multiple bytes
'''
newArgs = [] newArgs = []
# For each defined argument in the capability definition # For each defined argument in the capability definition
for arg in range( 0, len( capabilities_dict[ items[0] ][1] ) ): for arg in range( 0, len( capabilities_dict[ items[0] ][1] ) ):
argLen = capabilities_dict[ items[0] ][1][ arg ][1] argLen = capabilities_dict[ items[0] ][1][ arg ][1]
num = items[1][ arg ] num = items[1][ arg ]
byteForm = num.to_bytes( argLen, byteorder='little' ) # XXX Yes, little endian from how the uC structs work
# Set last bit if value is negative
if num < 0:
max_val = 2 ** (argLen * 8)
num += max_val
# XXX Yes, little endian from how the uC structs work
byteForm = num.to_bytes( argLen, byteorder='little' )
# For each sub-argument, split into byte-sized chunks # For each sub-argument, split into byte-sized chunks
for byte in range( 0, argLen ): for byte in range( 0, argLen ):

View File

@ -1,17 +1,32 @@
Name = mouseTest; Name = mouseTest;
Version = 0.3d; Version = 0.2;
Author = "HaaTa (Jacob Alexander) 2016"; Author = "HaaTa (Jacob Alexander) 2016";
KLL = 0.3d; KLL = 0.3d;
# Modified Date # Modified Date
Date = 2016-03-20; Date = 2016-03-21;
U"1" : mouseOut( 1 ); # mouseOut
U"2" : mouseOut( 2 ); # Arg1, button, 1-8
U"3" : mouseOut( 3 ); # Arg2, mouse x relative axis -127 to 127
U"4" : mouseOut( 4 ); # Arg3, mouse y relative axis -127 to 127
U"5" : mouseOut( 5 );
U"6" : mouseOut( 6 ); U"1" : mouseOut( 1, 0, 0 );
U"7" : mouseOut( 7 ); U"2" : mouseOut( 2, 0, 0 );
U"8" : mouseOut( 8 ); U"3" : mouseOut( 3, 0, 0 );
U"4" : mouseOut( 4, 0, 0 );
U"5" : mouseOut( 5, 0, 0 );
U"6" : mouseOut( 6, 0, 0 );
U"7" : mouseOut( 7, 0, 0 );
U"8" : mouseOut( 8, 0, 0 );
U"Up" : mouseOut( 0, 0, 1 );
U"Down" : mouseOut( 0, 0, -1 );
U"Left" : mouseOut( 0, -1, 0 );
U"Right" : mouseOut( 0, 1, 0 );
U"W" : mouseOut( 0, 0, 5 );
U"S" : mouseOut( 0, 0, -5 );
U"A" : mouseOut( 0, -5, 0 );
U"D" : mouseOut( 0, 5, 0 );