Hi,
oboy wrote:
OK, merging input service with GUI/Console-service sounds good.
How is a console service often designed?
Like this?
1. Program starts, sends message to input service
2. Input service creates buffers and everything needed for a console
3. Input service iterates through a list of input drivers selected (keyboard, mouse etc) and sends a message to each one
4. An input driver receives the message and creates buffers etc needed by the driver, returns a handle to the input service.
5. Input services stores all handles in the data for the console and returns a handle for the console to the program
6. stdin and stdout are mapped to that handle
Everyone does things differently, but here's my method:
1. Program starts and creates a "client connection" to the User Interface (the GUI/Console-service), which uses a defined protocol for all user related things (video, sound, mouse, keyboard, etc) via. messaging/IPC.
2. The input service (and all other user related device drivers) also create a connection to the User Interface, which uses a "device specific" protocol via. messaging/IPC.
3. The input driver sends "packets" of data to the User Interface - for keyboards this consists of an 8 bit keycode, a 32 bit unicode character and a set of state flags (capslock state, numlock state, scrolllock state, control key states, shift key states, alt key states).
4. When the User Interface receives data from an input driver it checks for global actions (control+alt+delete, control+tab, control+shift+tab, etc), and handles them.
5. If it wasn't a global action, then the User Interface sends the keypress data to an optional "keypress processor", which is a utility that handles keyboard macros and "Input Method Editors" (see notes below). After processing this utility sends the modified keypress data back to the User Interface.
6. The User Interface ends up sending the data to the currently active client connection (application, window, screen or whatever) via. messaging/IPC.
For some languages (Japanese, Korean, Chinese, etc) where there's thousands of symbols/characters (one for each word), the keyboard is used to enter parts of a word and the Input Method Editor allows the user to select a word (or a symbol/character) that begins with the parts of the world entered. For example (in English), the user would press 'c' then 'a', the IME would present a list of words that start with 'ca' (cat, car, camera, etc), the user would select the word they want (camera), and then the IME would send the selected word/symbol/character to the User Interface.
For a better description, see
http://www.answers.com/topic/input-method-editor.
I use the same thing for keyboard macros, which allows the user to assign a sequence of keypresses to a specific key. For example, you could define "alt+N" to be your email address so that instead of typing it out every time you just press the shortcut key, or "alt+w" might start a web browser.
Cheers,
Brendan