how can I use applescript to type?

how can I use applescript to type in a specified area on the screen? I've tried the 'keystroke' command, but it doesn't seem to work. also, how can I use applescript to display an image? thanks a lot if you answer. here's the code I have so far:

set theText to text returned of (display dialog "Put what you want to autotype here." default answer "" buttons {"OK", "cancel"} default button 1)
display dialog "select where you want me to type " & theText & " Your text will be typed in the area selected. you have 10 seconds to select once you click 'OK'" buttons {"OK"}
delay 10
say "typing"
--command for typing here
end
end
end

tell application "System Events"
    set textToType to "text here"
    keystroke textToType
end tell

Replace within the quotes of "text here" to what ever you need.


You can also use key code to type individual keys or achieve most functions using your keyboard.


key code 8 using {command down, shift down} --> ⌘+shift+C

Here is the full list of key codes: https://eastmanreference.com/complete-list-of-applescript-key-codes