Observables, Typewriter, KeyNotification issues

Using Alpha36.1

I have been using the typewriter [text] node which is very handy.
I want to filter so it only takes alphabet input and ignores numerals.

I’ve made a modified version called TypewriterFilter and I’m using the Where [Reactive.Observable] node to filter out observables where the keycode matches the codes for numeric keys. It’s not working although according to the ioboxes in the observable region the filtering logic is correct.

Any ideas?


PatchesTypewriterFilter.zip (23.2 KB)

try the where Reactive process node instead of the one in the observable category. always use our wrappers in the reactive category, unless you are building a big observable computation on create or in a cache region or so… also ForEach (Keep) reactive should work, which can have stateful nodes inside if you need them.


Ok I’ve switched to using a ForEach (keep) region but still having trouble. I’m getting errors on the KeyCode (KeyNotification) node: Object reference not set to an instance of an object.

As far as I understand the observable doesn’t run unless an object is passed in for it to deal with so I’m not sure what the problem is?


PatchesTypewriterFilter2.zip (25.1 KB)

the problem is the CastAs, not all notifications fit your type, so you will have null when events come in that are not instances of your desired type. so either put the OfType reactive before the ForEach or put everything inside an If region connected to the Success pin of the CastAs node.

Ah thanks for your patience with me @tonfilm , ok the cast problem is fixed.

After that I ran into a few more issues but I worked it out.
I’ll document here for anyone else having trouble with keyboards in VL in future.

-The Notifications [IO.Keyboard.KeyboardDevice] node takes a Keyboard device as input and generates observables of the KeyNotification type. Pressing one key generates multiple observables.
-Using the ForEach (keep) region you can operate on individual notifications in the observable stream.

-The KeyNotifications have two subtypes, KeyPressNotifications and KeyCodeNotifications. At a glance these carry similar data.

-KeyPressNotifications carry a keyChar payload. Can be converted into a primitive char using the KeyChar node.
-KeyPressNotifications don’t indicate wether the key is up or down, they just exist while it is pressed.

-KeyCodeNotifications carry a KeyCode payload. That can be convered into the ‘Keys’ datatype using the KeyCode node
–The ‘Keys’ datatype can than be converted into a key name string using the ToKeyName node. (There is also a FromKeyName node)
–KeyCodeNotifications come in ‘KeyUp’ and ‘KeyDown’ variations

-The typewriter implementation in VL uses KeyPressNotifications for inserting characters, so if you want to prevent certain characters getting through you have to filter for KeyPress notifications, convert them to chars, and check if they match a list of chars you do or don’t want.
-But it uses the KeyCodeNotifications for backspace and special characters.
-So your filter needs to keep all KeyCodeNotifications and only desired KeyPressNotifications.
-To test if a notification is of the KeyCodeNotification type there are two nodes, IsKeyUp and IsKeyDown. (or you can just cast it to the type and check the success of the cast).


PatchesTypewriterFilterFixed.zip (26.6 KB)

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.