This hint will let you toggle the state of the Character Palette and Keyboard Viewer via AppleScript and a hot key -- activate and hide the panels just by pressing their assigned hot keys. I'll use Proxi for the hot key assignments, but the AppleScripts should work with any such program -- Spark, Keyboard Maestro, Quickeys, Butler, etc. (This hint is similar to this earlier hint, but provides a toggle functionality and works in 10.5.)
Install Proxi, then open the Proxi Editor. Choose Insert Trigger » Hotkey Monitor from the Action menu beneath the Triggers portion of the Proxi Editor window (or drag it in there from the Components window). Replace the selected text (Hotkey Monitor) in the new Trigger with Toggle Character Palette. Click Set in the right half of the Editor window. Press Control-~ (tilde), or the key combination of your choice, to set the trigger's keyboard shortcut.
Choose Insert Task » AppleScript from the Action menu beneath the Tasks portion of the Proxi Editor window. (Double-click AppleScript in the Tasks portion of the window to rename it if you like.) Click Run Custom AppleScript in the right half of the Editor window. Copy and paste the following code into the Run Custom AppleScript text field:
Follow the same steps as above to create a new Hotkey Monitor trigger in Proxi, name it Toggle Keybaord Viewer, assign a different keyboard shortcut, and set its custom AppleScript code to this:
[robg adds: These both worked as described in my testing, using Butler as the vehicle. The original source code for both scripts can be found on the author's site.]Mac OS X Hints
http://hints.macworld.com/article.php?story=20080326102502259