galaktor / gostwriter

A virtual keyboard for linux, which makes use of /dev/uinput to inject key events.
GNU General Public License v3.0
24 stars 7 forks source link

Expose more convenient API for common keys #3

Open galaktor opened 10 years ago

galaktor commented 10 years ago

For ASCII alpha-numeric characters and very common keys such as Enter, shift, ctrl, arrows... create an abstraction on the keyboard the exposes those with utmost simplicity, i.e.

type LazyKey interface { Press() error Release() error Punch() error }

type LazyKeyboard interface { A() LazyKey B() LazyKey // ... etc Enter() LazyKey }

// usage func main() { // wrap keyboard in lazy wrapper kb := gostwriter.LazyKeyboard(gostwriter.New("foo"))

// be a good girl and handle errors
err := kb.A().Press()
// handle the error somehow

// or ignore errors, whatever
kb.A().Punch()

}

galaktor commented 10 years ago

I was just thinking, a "fluent" package with a more functional API using higher order functions and linked via stateful args/return value struct could work. Result might look something like:

kb := gostwriter.New("myKeyboard")
f := fluent.Wrap(kb) // get the fluent wrapper
f.Press(fluent.Keys().Shift()).Then.Punch(fluent.Keys.A().B().C()).Then().Release(fluent.Keys.Shift())

and so on. Maybe some namespace/package trickery can get rid of boilerplate (or shorten) the "fluent" part, which obviously doesn't feel that fluent...