udev – Reassign the BTN_STYLUS event to the standard keyboard key?


I am trying to use a VEIKK graphics tablet on Kubuntu 19. So far I have a satisfactory setup, but the only thing left is to remap the pen buttons. I feel like I have all the ingredients to make it, but I can't figure out how to put it all together.

evtest Identify the entry in question:

/dev/input/event3:  VEIKK S640 Pen

Running evtest in this post reports:

Input driver version is 1.0.1
Input device ID: bus 0x3 vendor 0x2feb product 0x1 version 0x100
Input device name: "VEIKK S640 Pen"
Supported events:
  Event type 0 (EV_SYN)
  Event type 1 (EV_KEY)
    Event code 330 (BTN_TOUCH)
    Event code 331 (BTN_STYLUS)
    Event code 332 (BTN_STYLUS2)
  Event type 3 (EV_ABS)
    Event code 0 (ABS_X)
      Value  15580
      Min        0
      Max    98304
      Resolution       1
    Event code 1 (ABS_Y)
      Value  13040
      Min        0
      Max    32768
      Resolution       1
    Event code 24 (ABS_PRESSURE)
      Value   1670
      Min        0
      Max     8192

And actually, when I press the pencil button, I see

Event: time 1586123903.365325, type 1 (EV_KEY), code 331 (BTN_STYLUS), value 1

followed later by

Event: time 1586123903.499328, type 1 (EV_KEY), code 331 (BTN_STYLUS), value 0

What I would like to do is simply replace these events generated with different events let's say

type 1 (EV_KEY), code 30 (KEY_A), value 1

for the first and similarly for the second, so pressing the pencil button is the same as pressing the a Down (and up) key on the keyboard.

There are several closely related questions on this site, this being probably the closest one, but the proposed solutions and the final solution are quite confusing. I've also prototyped by writing a python-evdev script to "filter" these events into something, but that comes with its own problems.

So is there a standard way to achieve this using udev?