Mapping keypress to slider ranges

Official forum for open source FreePIE discussion and development.
Post Reply
Ruprecht
One Eyed Hopeful
Posts: 1
Joined: Sat Mar 25, 2023 9:26 am

Mapping keypress to slider ranges

Post by Ruprecht »

Hello everyone,
I'm new to FreePIE and currently trying to map keypresses to slider ranges. I'm doing this in order to map a zoom function to the slider, with the zoom being set to 0 when the slider reaches the bottom and increasing/decreasing as you move the slider up/down. The zoom is controlled via three possible commands (increase zoom by one level, decrease zoom by one level, set zoom to 0); the commands can be mapped to keys. There are 9 different zoom levels (so 10 "zoom states" including "0 zoom") in the application.

I ran into two issues so far that I couldn't find any solution for.

This is the code I'm currently working on:

Code: Select all

if joystick[1].sliders[0] < -900:
	keyboard.setPressed(Key.W)
elif -800 > joystick[1].sliders[0] >= -900:
	keyboard.setPressed(Key.E)

diagnostics.watch(joystick[1].sliders[0])
1st issue: Key remains pressed
What I thought my code would do (from looking at a number of script examples):
When condition is triggered, key is pressed once.

What actually happens:
As long as the slider is in the specified range, the according key gets pressed over and over again (like if it was held down on the keyboard), even if the slider isn't moving (watch value for the slider remains static).



2nd issue: How to trigger keypress depending on from where the range is added?
In order to use the zoom function correctly, the script would need to know if a certain slider range is reached from top or bottom, as I cannot directly switch to any zoom level besides "0". Does anyone have an idea how to tell FreePIE that, for example, the range -800 > x >= -900 is reached by crossing -900?


I hope someone has done something like this before. It doesn't feel like something ultraspecific (mapping keypresses to axis/slider ranges, I mean), but somehow I couldn't find anything even remotely like this.
Jabberwock
Cross Eyed!
Posts: 197
Joined: Mon Mar 02, 2015 3:58 pm

Re: Mapping keypress to slider ranges

Post by Jabberwock »

Yes, the command should work that way, I am not sure why it does not, it certainly does with joystick buttons. You can try the version with boolean, it should output the value once, but then you have to reset it (by changing the boolean to false).

You can work around that using a variable - e.g. check the value of the axis (say you are in range 1), if the value of the range is different than a value remembered in a variable, do the action and update the variable to the current range. Incidentally, this also solves your second issue - if the remembered last range is higher than the current one, then you are going down and vice versa. Still, it might be hard to get it work as you want it to - any restart of the program or software would desync the ranges and the zoom level. Is 0 the lowest zoom value? That would help, as you could hardcode it for the lowest range, so you can always reset it that way.
Post Reply

Return to “FreePIE”