Musings on Control
A while back I wanted a simple system for automating sending text messages via the internet.
There are a few friends I’ve got on different plans where I can send them messages via a form on the internet. And I wished to automatate this so I could say “at 9pm send this”.
So I came up with another plan.SendKeys
SendKeys is a thing that Visual Basic programmers might recognise, it’s a simple means of injecting keypresses into windows.
I wrote some XLib code for faking key presses + releases into random windows and all is good.
I could then write a simple parser which understood two options:
- Executing a program
- Sending keys to it.
My first program was:#!/home/skx/bin/faker execute mozilla-firefox http://www.random.com/ sendkeys "[tab]5555-1234[tab]This is a message[tab][ret]"
This works, but it doesn’t allow for much customization, or flexability.
It also didn’t deal well with the popup windows I have to use for some programs, where I want to use something more complex.
I realised I needed to use conditionals:if ( ! findWindow( "mozilla-firefox" ) ) execute( "mozilla-firefox" ); fi ..
So I have three choices:
- Write a proper grammar and parser.
- Rewrite my code as a Perl/Ruby/Python extension and do the logic in that.
- Hookup my functions “execute”, “sendkeys”, “findwindow”,etc to the C intepretter cint
I think I like the idea of the last one best .. but I’m probably going to be doing one of the first two.
Perl is my favourite language, but this would be a fun way of learning to write Ruby extensions.
Of course now I need to think of a name!
I guess we’re talking of something that is analagous to “expect”, but for GUIs.
Right now I’m thinking of something like XLib::SendKeys.