Replies: 2 comments 2 replies
-
|
I've been meaning to add some examples to the config reference. If you just want to cut to the chase, there's an example at the bottom that you should be able to crib from without having to get into all of the technical details. But I'll start with an explanation of how this works, in case you want to be able to extend the example beyond just the one shift button. The system is pretty technical, in that it requires understanding a little bit about binary arithmetic and Boolean logic functions, but once you have those basics down, the core rule that makes it work is really pretty simple. The key to how this whole scheme works is "bit masking", which is another term for the "bitwise AND" operation, where you perform the AND operation on two binary numbers, bit by bit. For a single bit, the AND function is pretty straightforward: A AND B = 1 if both A and B are 1, and 0 for every other case - in other words, it's TRUE (1) if BOTH A AND B are both TRUE, and FALSE (0) otherwise. Extending this idea to integer values, you write out the binary version (that is, the base 2 arithmetic representation) of the two numbers, and you apply the AND operation to each digit position in the number. For example, to calculate 2 AND 3, you write the binary versions - 2 = 10, 3 = 11 - and then you AND each bit: so the first (left) bit is "1 AND 1 = 1", and the second (right) bit is "0 and 1 = 0". Then you string the bits together again and make it into a new binary number so 2 AND 3 (decimal) = 10 AND 11 (binary) = 10 (binary) = 2 (decimal). The other important bit operation is OR. A OR B is TRUE when EITHER A OR B is TRUE: 0 OR 0 = 0, 0 OR 1 = 1, 1 OR 0 = 1, 1 OR 1 = 1. This extends to larger numbers in the same way as AND, writing the two numbers in binary, and applying it bit-by-bit. So 2 OR 3 (decimal) = 10 OR 11 (binary) = 11 (binary) = 3 (decimal). Note that JSON lets you write numbers in binary format explicitly, which might make this easier to follow in the config file. To write a number in binary, start it with a "0b" (zero, lower-case B) prefix: 0b10 is the same as decimal 2, 0b11 is decimal 3, 0b1000 is decimal 8 etc. The Pinscape shift key scheme uses the bit masking/bitwise AND operation to determine when a key is affected by shifting. Here's the core rule: A button activates when the "Global Shift State" AND the button's shiftMask equals the button's shiftBits. The "Global Shift State" is the OR combination of the If you just want to create a single SHIFT button, bringing all of this binary arithmetic to bear is a lot of overkill in terms of learning curve, but fortunately it ends up pretty simple in terms of what you actually have to put in the JSON. For just one SHIFT button, we just need one bit for the "Global Shift State" business, so let's use the first bit, 1 (binary), which we write in JSON as Okay, so that gives us our shift button, on GPIO port GP5. Press that button, and the Global Shift State value - the bitwise OR combination of the Now we just need to define a button with a shifted function. This requires TWO new button entries, one for the SHIFTED function of the button, and one for the UNSHIFTED function of the button. In both cases, we want this button to be sensitive to the The other thing we have to add to each affected button is a Putting that all together, here's the basic outline of what you need to define when there's a single shift button in your system:
Now to the example! This should define one shift button on GP5, and a two-function button on GP6, which acts as the Volume Down key when the shift ISN'T pressed, and the Volume Up key when the shift IS pressed: You should be able to follow the pattern for the Volume Down/Volume Up buttons above to create any number of other shifted buttons. All you have to do to make them shifted is put in the shiftMask and shiftBits values as shown. |
Beta Was this translation helpful? Give feedback.
-
|
I should have mentioned the SHIFT-AND and SHIFT-OR option - tPulse is the way to get the SHIFT-OR version, as you figured out. You're right that Windows ignores the Keyboard Volume Up and Keyboard Volume Down keys, whereas it does have built-in handling for the Media Volume Up and Down keys, so those would have made a better example. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently i'm a bit lost with the "shiftmode" function for my buttons.
I want to set my Startbutton (key 1) to also act as a shift button.
but honestly i can't figure it out how that actually works...
do i have to use the shiftbits description on all other buttons that would have a 2nd function?
it would be really helpful if someone could post a working example of maybe 2-3 buttons, so i get an idea of how it works.
tbh, the config helper is not very helpful at that special case, or i simply didn't get it :(
Beta Was this translation helpful? Give feedback.
All reactions