--
You received this message because you are subscribed to the Google Groups "go-uik" group.
To view this discussion on the web visit https://groups.google.com/d/msg/go-uik/-/AGmwoUIeIsEJ.
To unsubscribe from this group, send email to go-uik+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/go-uik?hl=en.
--
You received this message because you are subscribed to the Google Groups "go-uik" group.
To post to this group, send email to go-...@googlegroups.com.
To unsubscribe from this group, send email to go-uik+unsubscribe@googlegroups.com.
One thing that I would like to have done in the near future is settle on a good way for go.wde to provide keyboard input. Right now it sends an int and a string, for the code and printable letter. For regular letter this works fine on all platforms. For special keys (delete, arrows, alt, things like that), each platform seems to have a different set of codes. I want something to filter this and send something uniform, and to also track key chords nicely. Any interest in this?
I wouldn't mind working on that. However, it sounds like we have some design decisions to make first.
One idea I had is, since Go does everything utf8 by default, attempt to take advantage of that. Instead of inventing yet another set of codes, could we do something like pass a utf8 arrow character for cursor keys (→, ←, ↑, or ↓). I'm sure we could agree on appropriate symbols for shift, alt, control, and super as well. This would also simplify things a pinch, because you'd only have to send the character, instead of both the code and printable letter.The only downside I could think of would be if somewhere there existed a keyboard with actual physical buttons for the characters we've chosen. But I doubt such a keyboard exists.
type KeyEvent struct {
Glyph string
}
type KeyDownEvent struct {
KeyEvent
Letter string
Chord string
}
Schemes like this are tempting, and they make for extremely readable code. One strong downside that you didn't mention is it can be very difficult to *write* code that uses a lot of unicode glyphs. I ran into this issue with a statistics library I wrote a while back. There are εs and αs all over the place, making it very familiar for people who do a lot of statistics, but it is very difficult to type those letters unless you take some time to set up your keyboard.I would much rather send "left" than "←". This is what xgb already does ("Left_arrow" actually).Perhaps something liketype KeyEvent struct {
Glyph string
}
type KeyDownEvent struct {
KeyEventLetter stringChord string
}The Glyph refers to the actual key-press that triggered this event. So it could be "a", "backspace", "delete", "up arrow" etc.The Letter refers to an actual typed thing to go on the screen, and "" if nothing. So, "a", "A", "!", but not "backspace" etc. Something to be inserted directly into the viewable text.And the Chord refers to the set of keys being held down, separated by a "-" and in some sorted order. So, typing "A" would cause these two events:{ Glyph: "shift", Letter: "", Chord: "shift"}, { Glyph: "a", Letter: "A", Chord: "shift-a"}What do you think?
I like it. I especially like the separate Glyph and Letter variables. They provide clarity without re-introducing the random arbitrary numbering scheme. Out of curiosity, why did you move Glyph into a separate struct? Is it because KeyEvent will be carrying all values common to both KeyDownEvent and KeyUpEvent?
And also (I'm not trying to be antagonistic, but I like to be thorough when it comes to design decisions),
would it make more sense to have Chord be []string? Since it's holding multiple values? Checking for a chord (which would become a common paradigm in event programming) would look like "len(Chord) > 0" rather than the more verbose "len(strings.Split(Chord, "-")) > 0".
The thing with having it be a single string is that it makes comparison very easy. You can do ke.Chord == "ctrl-alt-delete", and since you know the glyphs will be in sorted order you know that you don't have to check for "alt-ctrl-delete" too. I also thinking that checking for the existence of *any* chord, ie "len(strings.Split(Chord, "-")) > 0", will be very rare, while checking for the existence of a particular chord will be very common. String comparisons can also be done efficiently in a type switch, while slice comparisons cannot.
Okay, I can live with that, as long as we ALWAYS put them in the same canonical order every time. I'm having gut-wrenching flashbacks to Qt events where I would constantly check for both "SHIFT+CTRL+D" and "CTRL+SHIFT+D". And don't even get me started about when there were three modifiers...
For the ordering, I guess a first idea is to list all modifier keys first, in alphabetical order, and then list all typings keys, also in alphabetical order. Typing keys include backspace, delete, return, since they modify a normal text input when typed by themselves. Things like control, shift etc, don't do anything if you type them by themselves, so they are modifiers.
It actually doesn't really matter what we do specifically, as long as it's exactly the same each time. Most people will print out the key chord for the combo they want and copy that string into their code.
What platform are you working from, btw? When you have something I'd like to take a look at it and map out the other two platforms.
I think the unifying bit would be best as a function that maps what comes in as code and letter to the struct { Glyph string; Letter string} type. The stuff to map that into chords... perhaps that code would go in go.uik rather than go.wde? In any case it'd be separate.
You may have to recompile and install the gomacdraw xcode portion as well. I had to make a quick tweak to it.
If you want, I can send you a pull request in Github, but I'll try to get that super key working in the mean time.
I'm not sure yet if that mapping code should go in go.uik. I like the idea of all system dependent codes going in go.wde, leaving only the Glyphs, Letters, and Chords for go.uik.
What change did you need to make?
btw make sure to add yourself to go.wde/AUTHORS before you pull-request.
I'm thinking a new event type KeyChord struct { Chord string }. A key stroke that is part of a chord should not be interpreted as a typed letter, so wde shouldn't let it be a possibility.
--
You received this message because you are subscribed to the Google Groups "go-uik" group.
To view this discussion on the web visit https://groups.google.com/d/msg/go-uik/-/M5lzCGNACMwJ.
I wouldn't be suprised if apple simply didn't report this key. Absolutely all menu chords use the command key, and it is used for nothing else as far as I'm aware.
Do you think you could create a set of constants in a new file go.wde/keys.go that looks liketype Glyph stringconst (KeySuper Glyph = "super"KeyLeftAlt Glyph = "left_alt"KeyLeftArrow Glyph = "left_arrow"KeyA Glyph = "a"KeyPercent Glyph = "%")etc?
So why does it not recognize the super key? In the old version when you hit command on mac, it reports key code 54 or 55, depending on which one...