keyboard layout help

Hey,

I require to change frequently between to different keyboard layouts, I was wondering if it is possible to do it using appleScript. the ideal thing would be if “layout 1” was selected as default and if a key like spacebar is held for more than a certain time it changes to “layout 2” and when released it changes back to layout 1. I’m running mac os tiger

Thanks