Giter Site home page Giter Site logo

Comments (6)

jfedor2 avatar jfedor2 commented on July 17, 2024 1

The runaway mouse cursor actually means it's working, believe it or not. To stop it from happening, disable the "Unmapped inputs passthrough" option in the "Settings" tab.

To map directions on an analog stick to keys, use a configuration like this:

Expression 1:

0x00010030 input_state -128 add dup mul /* stick x^2 */
0x00010031 input_state -128 add dup mul /* stick y^2 */
add /* x^2 + y^2 */
sqrt
1 store /* sqrt(x^2+y^2) */
0x00010030 input_state -128 add
0x00010031 input_state -128 add
atan2
2 store /* stick angle */

2 recall 45 gt /* angle > 45 */
135 2 recall gt /* angle < 135 */
mul
1 recall 64 gt /* deadzone */
mul
3 store

2 recall -135 gt /* angle > -135 */
-45 2 recall gt /* angle < -45 */
mul
1 recall 64 gt /* deadzone */
mul
4 store

2 recall 135 gt /* angle > 135 */
-135 2 recall gt /* angle < -135 */
bitwise_or
1 recall 64 gt /* deadzone */
mul
5 store

2 recall -45 gt /* angle > -45 */
45 2 recall gt /* angle < 45 */
mul
1 recall 64 gt /* deadzone */
mul
6 store

Then create mappings with Register 3, 4, 5, 6 as their inputs and whatever keys you want pressed as the outputs.

This gives you four buttons, one per cardinal direction. A similar thing could be done for 8 directions by adding four more similar entries and adjusting the angles.

As you can see with registers you're not limited by the number of expression slots as everything can go into the same slot pretty much.

from hid-remapper.

jfedor2 avatar jfedor2 commented on July 17, 2024 1

Yeah, this is because the analog stick on a gamepad sends 0-255 values and the neutral position is 128, not 0.

After you connect it, or turn everything on, if you don't touch the gamepad, it doesn't send anything until you press some buttons or move the sticks. And HID Remapper's internal state for those inputs defaults to 0, which translates to northwest on the analog stick.

An inelegant solution to this is to change this part of the expression:

2 recall -135 gt /* angle > -135 */
-45 2 recall gt /* angle < -45 */
mul
1 recall 64 gt /* deadzone */
mul
4 store

to read:

2 recall -134 gt /* angle > -134 */
-45 2 recall gt /* angle < -45 */
mul
1 recall 64 gt /* deadzone */
mul
4 store

Making a 1-degree wide gap in the northwest corner that corresponds to the sticks initial position.

A more elegant solution would involve having a flag that basically means "have we seen movement on the stick yet".

Let's say register 32 will be that flag.

Then our expression would look like this:

/* update register 32 to 1 if there's a change in left stick state */
32 recall
0x00010030 input_state
0x00010030 prev_input_state
eq not bitwise_or
0x00010031 input_state
0x00010031 prev_input_state
eq not bitwise_or
32 store

0x00010030 input_state -128 add dup mul /* stick x^2 */
0x00010031 input_state -128 add dup mul /* stick y^2 */
add /* x^2 + y^2 */
sqrt
1 store /* sqrt(x^2+y^2) */
0x00010030 input_state -128 add
0x00010031 input_state -128 add
atan2
2 store /* stick angle */

2 recall 45 gt /* angle > 45 */
135 2 recall gt /* angle < 135 */
mul
1 recall 64 gt /* deadzone */
mul
32 recall mul
3 store

2 recall -135 gt /* angle > -135 */
-45 2 recall gt /* angle < -45 */
mul
1 recall 64 gt /* deadzone */
mul
32 recall mul
4 store

2 recall 135 gt /* angle > 135 */
-135 2 recall gt /* angle < -135 */
bitwise_or
1 recall 64 gt /* deadzone */
mul
32 recall mul
5 store

2 recall -45 gt /* angle > -45 */
45 2 recall gt /* angle < 45 */
mul
1 recall 64 gt /* deadzone */
mul
32 recall mul
6 store

The 32 recall mul part zeroes the value that we put in registers 3, 4, 5, 6 if there hasn't been any change in left stick state yet.

Though this is not perfect either, at least while you work on the configuration - when you save the configuration to the device, the input states are reset, but the register states aren't. So you get the same problem. But during normal use it should be fine. Something to think about for me perhaps.

from hid-remapper.

CrowKing63 avatar CrowKing63 commented on July 17, 2024

Just in case, I tried another keyboard at home (I don't know the manufacturer because it's a cheap bundle), but it doesn't turn on at all. Am I doing something wrong? Is the board I bought defective? I don't know...

from hid-remapper.

CrowKing63 avatar CrowKing63 commented on July 17, 2024

It's a really simple and beautiful solution. Thank you for letting me know! I just turned off and tested all of the "Unmapped inputs passthrough" options, and made sure my mouse cursor was properly monitored without running away. Yay !

Looking at the Expressions 1 you wrote down, the method I envisioned was really an infantile idea at the level of 'if ~ else' (laughs). Thank you once again. I will take the time to open the code you wrote carefully and make good use of the registers.

Thank you.

from hid-remapper.

CrowKing63 avatar CrowKing63 commented on July 17, 2024

I'm sorry, but I have one more question.

Every time a device is connected for the first time, when the computer is turned on with the device connected, or when it is initialized by changing the settings, it starts with a certain input held.

I've tested it in many ways, and for now it looks like the output you set for Register 4 as input starts with hold.

(Although I changed the register number) If I set a scroll-up on Register 4, the scroll-up starts with a hold every time a device starts up, and when I assign a right mouse button to Register 4, the device will also start as if I were holding that button.

Register 4 is in the west direction, I tested it with the right stick just in case my left stick was defective, but it showed the same symptoms perfectly.

This symptom only occurs at the beginning, and disappears with other manipulations. I have also tried to explicitly initialize the register but it doesn't seem like the cause of the problem. I don't know what the hell is wrong.

I'm worried if Iā€™m asking too a sa scrimbary question. Sorry.

from hid-remapper.

CrowKing63 avatar CrowKing63 commented on July 17, 2024

Aha! I understood what was going on. Thank you so much for the easy and kind explanation. And thank you again for the solutions you wrote down. As you say, the solutions are elegant. It's like watching a puzzle game broadcast!

Wouldn't it be helpful to set the dead zone to reverse? Like 127 1 recall gt? It's fun because it feels like playing a game!

from hid-remapper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.