Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capturing arrow keys with F# and Eto.Forms

Tags:

.net

f#

gtk3

eto

Using F# and Eto.Forms on Linux, with the Gtk3 backend.

EDIT: Adding updates to this google groups thread. My current best theory is that the way Eto adds keypress events to a widget in its Gtk backend does not let you capture events before a default handler both handles them and stops the signal from propagating further.


I'm trying to capture KeyDown events in a form:

let f = new Form(Topmost=true, ClientSize = new Size(600, 480))  f.KeyDown.Add(fun e ->   match e.Key with   | Keys.Up -> cursor.Move(Move_Up)   // ...   ) 

but I'm running into this issue: Up, Down, Left and Right arrow keys do not trigger KeyDown event

I cannot figure out how to follow the solution provided there (override PreviewKeyDown and set e.IsInputKey = true). I tried adding the following:

f.PreviewKeyDown.Add(fun e -> e.IsInputKey <- true) 

but that just complained that f.PreviewKeyDown did not exist.


EDIT: It might be this Gtk#-specific issue rather than the one above

As of release 0.15, Gtk# started using the CONNECT_AFTER flag when connecting event handlers to signals. This means that the event handlers are not run until after the default signal handlers, which means that the widget will be updated when the event handlers run. A side effect of this change is that in the case where default handlers return true to stop signal propagation, Gtk# events will not be emitted.


Further detail: If I hold down a modifier key as well (e.g. shift + up arrow), then KeyDown triggers and e.Key does match Keys.Up. Also KeyUp always triggers, even when KeyDown does not.

like image 593
Martin DeMello Avatar asked May 01 '16 10:05

Martin DeMello


People also ask

What is the shortcut for arrow keys?

The technique : You keep the Alt key pressed (the key to the left of your Space bar), then you successively type the previously indicated numbers, then you finally release the Alt key, which will make the desired arrow appears.

Is there a faster alternative to using the arrow keys?

alt + J instead of ←


1 Answers

Try returning false in the event handler after you have handled the event.

like image 106
suleimanforever Avatar answered Sep 17 '22 09:09

suleimanforever