FLASH LED
Author SGP
Message No.

http://groups.yahoo.com/group/power-pro/message/14776

File Name FlashLED.powerpro
Requirements Event Plugin, KeyTrap Plugin, MiscPlugin, Win Plugin
Purpose flash the scroll-lock keyboard LED.
Notes:

Application: I use it in conjuction with a POP3 checker (not supplied) to get a visual indicator of incoming email messages when the display is turned off. The POP3 checker executes FlashLED.powerpro when a new message is detected in my inbox.

Usage: just run FlashLED.powerpro to start the LED flashing. Press the Pause key to stop FlashLED.powerpro turning off the LED.

Limitations: when the keyboard is locked on Win2K/XP pressing the Pause key produces no result until you actually login again.

Interesting techniques:
Look at the script code, comments (A), (B) and (C) compare different ways to send the scroll-lock key. In all cases, an event is spawn to repeatedly turn the LED on and off again (flash). Option (C) is preferred because it's the most portable and doesn't need an external plugin.

; FlashLED.powerpro - flash the scroll lock key LED
; until user presses Pause/Break key
;
;
; exit if this script is already running
if ( gvFlashingLED )
    quit(0)

; create event to flash the scroll lock LED
gvFlashingLED = 1
;
; {toany =exepath} below is used to avoid an error message on
; win2k when sending *keys if all windows are minimized.
; exepath must be a running app, i.e.,  use =powerpro or =winlogon (2k/xp)
;
; (A) :-( this steals focus on win2k
;local e = event.create(1,0,"keys {slow}{toany =winlogon}{scrolllock}","")
; (B) :-) this doesn't steal focus but needs Julien's new keybd plugin
;local e = event.create(1,0,"keybd.event(145,1)","")
; (C) :-) {to menu} doesn't steal focus: according to brucexs it tells PP
; to skip ensuring that there is a window to send the keys and to just stuff
; the keyboard buffer
local e = event.create(1,0,"keys {slow}{to menu}{scrolllock}","")

if( not e )do
    gvFlashingLED = 0
    quit(1)
endif

win.debug(date++time,scriptname++":","created LED flash event",e)

; wait for user to exit by pressing the Pause key
KeyTrap.Enable(1)
KeyTrap.WaitKey("19")

; stop flashing LED
event.destroy(e)
gvFlashingLED = 0
miscplugin.sleep("100")

; turn off LED for good
if ( KeyTrap.GetKeyState(1,145) )
    keys {slow}{scrolllock}

; unload KeyTrap unless global flag set elsewhere (presumably the user's PP initialization script)
if ( gvDisableKeyTrap )
    KeyTrap.Enable(0)

; The End