valpackett / evscript

A tiny sandboxed Dyon scripting environment for evdev input devices that lets you do e.g. xcape in Wayland | now on https://codeberg.org/valpackett/evscript
https://codeberg.org/valpackett/evscript
The Unlicense
121 stars 7 forks source link

The main example doesn't work #9

Closed paranormal closed 4 years ago

paranormal commented 4 years ago

Doing everything using documentation I have this error:

Ξ ~/evscript git:(master) ▶ evscript -f ev.dyon -d /dev/input/event19

--- ERROR --- In ev.dyon:

Type mismatch (#200): Expected [], found {} 9,19: for i len(evts) { 9,19: ^

hallettj commented 4 years ago

I had the same problem. You can fix it by changing for i len(evts) { ... } to for i { ... } as explained in Inferring range by indexing . I know it looks weird to write a for loop without declaring the range to iterate over. It seems that Dyon can see that i is used as an index into evts, and infers that it should iterate over every index of evts.

On Sat, Feb 22, 2020, 12:12 paranormal notifications@github.com wrote:

Doing everything using documentation I have this error:

Ξ ~/evscript git:(master) ▶ evscript -f ev.dyon -d /dev/input/event19

--- ERROR --- In ev.dyon:

Type mismatch (#200): Expected [], found {} 9,19: for i len(evts) { 9,19: ^

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/myfreeweb/evscript/issues/9?email_source=notifications&email_token=AAACLFUQIJIBNDSE3KADPXTREFMGFA5CNFSM4KZTBOX2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IPPZQAQ, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAACLFW4SUVI5WUXXGSTL4LREFMGFANCNFSM4KZTBOXQ .

paranormal commented 4 years ago

It works. Thank you.

Unfortunately I can't figure out if it is possible to remap ENTER key. I need my ENTER to work as RIGHTCTRL when hold, and as ENTER when just pressed.

xcape(mut should_enter, evt, KEY_ENTER(), [KEY_RIGHTCTRL()]) doesn't do the trick

hallettj commented 4 years ago

@paranormal I think you need to do it the other way around: remap your enter key to be right control (using xkb or some other means), and configure it to send enter on tap:

xcape(mut should_enter, evt, KEY_RIGHTCTRL(), [KEY_ENTER()])
paranormal commented 4 years ago

@paranormal I think you need to do it the other way around: remap your enter key to be right control (using xkb or some other means), and configure it to send enter on tap:

xcape(mut should_enter, evt, KEY_RIGHTCTRL(), [KEY_ENTER()])

Thank you for the tip. This is how it worked with an xcape. But it doesn't work the same with evscript. Somehow when run evscript, it restores the old RETURN map and on press it acts as RETURN, when ^C the evscript: the RETURN behaviour is preserved and acts as RETURN.

xmodmap -e "keycode 0x24 = Control_R"
xmodmap -e "add Control = Control_R"
fn main() ~ evdevs, uinput {
    should_enter := false
    loop {
        evts := next_events(evdevs)
        for i {
            evt := evts[i]
            xcape(mut should_enter, evt, KEY_RIGHTCTRL(), [KEY_ENTER()])
        }
    }
}
paranormal commented 4 years ago

It feels like evscript restores ENTER and it stops acting like CTRL, even after evscript is stopped remap no longer works, ENTER is an ENTER again.

valpackett commented 4 years ago

@paranormal are you still trying all that under xorg? you're not trying to xmodmap under wayland?

paranormal commented 4 years ago

@myfreeweb yes, I experimented under xorg, xcape is what I currently using and the reason I couldn't switch to sway.

Shall running the same recipe with remap and evscript work differently under wayland?

paranormal commented 4 years ago

I'll try, thank you.

paranormal commented 4 years ago

@paranormal are you still trying all that under xorg? you're not trying to xmodmap under wayland?

I've just tried it under sway, it doesn't remap ENTER back. But it doesn't work either.

paranormal commented 4 years ago

In /usr/share/X11/xkb/keycodes/evdev I changed RTRN to RCTRL after that my enter started working as CTRL. running evscript -f ev.dyon -d /dev/input/event19 where my HHKB sits changes nothing.

paranormal commented 4 years ago
//! [events]
//! keys = ['ESC', 'LEFTSHIFT', '9', '0']
fn main() ~ evdevs, uinput {
    should_enter := false
    loop {
        evts := next_events(evdevs)
        for i {
            evt := evts[i]
            xcape(mut should_enter, evt, KEY_RIGHTCTRL(), [KEY_ENTER()])
        }
    }
}
paranormal commented 4 years ago

Just rechecked everything again. Things from the main example works, it prints numbers on pressed shift keys. Enter key doesn't work at all, it behaves as a control.

paranormal commented 4 years ago

Just rechecked everything again. Things from the main example works, it prints numbers on pressed shift keys. Enter key doesn't work at all, it behaves as a control.

Just did another test with default /usr/share/X11/xkb/keycodes/evdev and trying to map LCTL to ENTER. Doesn't work, all other keys works, ENTER doesn't ((

Doesn't work.

xcape(mut should_enter, evt, KEY_LEFTCTRL(), [KEY_ENTER()])

Does work

xcape(mut should_enter, evt, KEY_LEFTCTRL(), [KEY_0()])

Could it be that the definition of KEY_ENTER() = 28 in src/stdlib.dyon is wrong?

valpackett commented 4 years ago

@paranormal I think what's happening is.. you remapped enter to something in xkb keycodes, and evscript is pressing enter again - it's getting the same remapping :D

I guess you could instead have evscript press something else that would be equivalent (numpad enter) or remapped differently (via xkb options in the compositor)??

paranormal commented 4 years ago

@myfreeweb I excluded this possibility. I returned everything back (default xkb keycodes) and applied the scenario to LCTL, it didn't trigger ENTER.

To reproduce this you just need this line (don't do any remapings):

xcape(mut should_enter, evt, KEY_LEFTCTRL(), [KEY_ENTER()])

it doesn't work for me.

paranormal commented 4 years ago

I've given it another shoot and found that I have to put //! keys = ['ESC', 'LEFTSHIFT', '9', '0'] in config, this wasn't mentioned in documentation.

After inserting line with //! keys = ['LEFTCTRL', 'RIGHTCTRL', 'ENTER'] it started working.