Testing for shift and tab at the same time

瀏覽次數:15 次
跳到第一則未讀訊息

Martin McDonough

未讀,
2016年7月17日 下午4:42:562016/7/17
收件者:fltk.general
I'm working on a text editor, and I am having trouble checking if both tab and shift are pressed at once.

I had to begin by disabling Fl::OPTION_VISIBLE_FOCUS, but even then it seems that holding shift and pressing tab causes an Fl::event_length() of 0.

Is there a way to actually handle getting a shift+tab? Or should I just manually use get_key? The documentation says this is very slow on X11, and it seems like a poor idea to have to check this every keypress.

Greg Ercolano

未讀,
2016年7月17日 下午6:36:072016/7/17
收件者:fltkg...@googlegroups.com
On 07/17/16 13:42, Martin McDonough wrote:
> I'm working on a text editor, and I am having trouble checking if both
> tab and shift are pressed at once.

If you've derived a class from Fl_Text_Editor, your handle() method should be able
to look for shift tab this way:

int YourEditorClass::handle(int event) {
switch (event) {
case FL_KEYBOARD: { // keyboard pressed?
switch ( Fl::event_key() ) {
case FL_Tab: // tab key?
if ( Fl::event_state() & FL_SHIFT ) { // shift key down at time tab key pressed?
// shift-tab
} else {
// just tab, no shift
}
[..]

That's the best way, and is what the FLTK widgets do internally.

Martin McDonough

未讀,
2016年7月18日 下午1:37:142016/7/18
收件者:fltk.general、erco_...@seriss.com
Ah, I had been using Fl::event_text and checking for "\t". Doing that, while shift is pressed tab just generates an empty event_text.

I'll try event_key and see what happens. Although I'd expect that event_text should still report "\t" anyway?

Greg Ercolano

未讀,
2016年7月18日 下午2:23:192016/7/18
收件者:fltkg...@googlegroups.com
On 07/18/16 10:37, Martin McDonough wrote:
> I'll try event_key and see what happens.

It should work so long as you read it in the context of
receiving an FL_PUSH or FL_RELEASE event in a handle() method.

> Although I'd expect that event_text should still report "\t" anyway?

Since event_text() returns the "text equivalent" of key strokes,
no, I wouldn't expect it to return anything, as there's no text
equivalent for Shift-Tab. An empty string is correct.

Tab is a valid white space ASCII character, shift tab is not,
and shouldn't map to any type of string to be inserted into
e.g. a text editor or input field.

event_key() is what you' want for catching specific keystrokes,
especially those without text equivalents.
回覆所有人
回覆作者
轉寄
0 則新訊息