How do I paste text in frontmost application?

I am trying to make a mouse paste in a body of text when you click on one of the buttons (something a Kensington mouse does with ease). I want to be able to paste the same text in MORE than one application. I have saved the clipboard, set it to what I want, and sent a keystroke using apple events to paste it into a window - this works fine if I activate a SPECIFIC application.
The problems come in when I want this to work for multiple applications - how can I detect the application that was active right before I launched the applescript, so as whichever had the frontmost window can be activated and then will get the paste?
Thanks
Eytan

This script by Kai Edwards does the deed. As is it just displays a dialog box and hides the script editor returning to the script when “ok” is clicked. You can modify it to do your deed - I haven’t modified it in any way because you didn’t post any script.

set lastProcess to getLastProcess()
tell application lastProcess to display dialog "Process \"" & lastProcess & "\""

to getLastProcess() -- Original by Kai Edwards --
	tell application "System Events"
		tell (get first process whose frontmost is true)
			set visible to false
			repeat while visible
				delay 0.1
			end repeat
		end tell
		set lastProcess to name of (get first process whose frontmost is true)
		if lastProcess is "Finder" and (count (processes whose visible is true)) > 1 then
			tell process "Finder"
				set visible to false
				repeat while visible
					delay 0.1
				end repeat
			end tell
			set lastProcess to name of (get first process whose frontmost is true)
			ignoring application responses
				set process "Finder"'s visible to true
			end ignoring
		end if
	end tell
	lastProcess
end getLastProcess

Thank you for your quick response. That worked perfectly.
Eytan