'pasteKey' message

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

'pasteKey' message

Post by lohill » Fri Aug 09, 2013 6:28 pm

Does the pasteKey message work? U would like to capture some clipboardData and do some processing on it before it shows up in the field. As a test I have put the code below in the script of a particular field. The script does not get executed when I paste into that field. Any ideas on how to do this?

on pasteKey
put the clipboarddata into tData
answer tData
end pasteKey

Thanks,
Larry

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: 'pasteKey' message

Post by dunbarx » Fri Aug 09, 2013 10:48 pm

It works. But the IDE traps it, so you have to suspend development tools to use it yourself. See the dictionary entry.

Craig Newman

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: 'pasteKey' message

Post by lohill » Sat Aug 10, 2013 12:00 am

Thanks Craig,

I read the dictionary for pasteKey and if I did the 'suspend development tools' correctly it still did not work for me. Does the fact that I have an Edit Menu with a choice for paste have any effect?

Larry

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: 'pasteKey' message

Post by dunbarx » Sat Aug 10, 2013 2:23 am

Must be. Can you pass the "pasteKey" message in the menu button script and check again?

I made a field with this script:

Code: Select all

on pastekey
   put the clipboardData && random(99) into me
end pastekey
Suspend development tools, get some text into the clipboard and paste a few times. Works.

Craig

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: 'pasteKey' message

Post by lohill » Sat Aug 10, 2013 5:59 pm

Craig,

Interesting situation because your suggestion definitely works on a test stack with a test field. I tried passing the "pasteKey" message in the menu button script of my stack. The 'compiler' would not accept "pass pasteKey" or "pass 'pasteKey'". I tried pass menu pick pWhich to no avail. Finally I tried: dispatch "pasteKey" to field "RadiScript" and it did work. The problem with that is that I don't want 'pasteKey' sent to that specific field every time someone pastes into some other field. Is there a way to get around that?

Regards,
Larry

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: 'pasteKey' message

Post by lohill » Sat Aug 10, 2013 9:26 pm

Craig,

I also learned that dispatch "pasteKey" to field "RadiScreen" works whether or not I have suspended the development tools. Now if I can get my field not to worry about the message at inappropriate times.

Larry

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: 'pasteKey' message

Post by dunbarx » Sat Aug 10, 2013 9:37 pm

Nice workaround.

Explicitly sending the message gives it its own life. Nothing wrong with taking that tack all the way.

Craig

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: 'pasteKey' message

Post by lohill » Sat Aug 10, 2013 11:41 pm

It has too much life! When I paste in another field that data seems to end up in my Radiscript field as well. How can I determine what field I was in when the pastKey was sent?

Larry

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: 'pasteKey' message

Post by dunbarx » Sat Aug 10, 2013 11:58 pm

Hi.

This is all solvable with "targets" and the like. But sometimes rethinking is called for when things get convoluted or overdependent.

What are your scripts?

Craig

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: 'pasteKey' message

Post by lohill » Mon Aug 12, 2013 6:00 pm

Hi Craig,
I'm sorry I took so long to get back. I messed around with 'target' for a while and couldn't get anywhere. I finally have come up with this that I think is working OK even though it is not very pretty. It seems that no matter how ugly I make it LiveCode doesn't seem to have any problems handling it. Here are parts of the code for what I now have:

Global variable declared in stack script: gScreenField

In button Edit for the stack:
case "Paste"
If the clipboard is "text" then paste
dispatch "pasteSpecial" to card "Screens"
break

In Script of card "Screens::
on pasteSpecial
global gScreenField
if gScreenField ="Radiscript" then
dispatch "pasteSpecial" to field "RadiScript"
end if
end pasteSpecial

In the script for field "Radiscript" of card "Screens"
on openField
global gScreenField
put the short name of me into gScreenField
end openField

on pasteSpecial
put the clipboarddata into tData
replace tab with space in tData
replace " " with space in tData
repeat with i=1 to number of lines of tData
put line i of tData into tLine
repeat
If char 1 of tLine=space then
put empty into char 1 of tLine
else
exit repeat
end if
put tLine into line i of tData
end repeat
end repeat
put tData into me
end pasteSpecial

Thanks for the all the suggestions. It is nice having you experts around.

Regards,
Larry

P.S. Is there a place that explains how to format these forum responses since the buttons for Code and Quote don't work?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: 'pasteKey' message

Post by dunbarx » Mon Aug 12, 2013 7:56 pm

Hi.

Glad you have a working gadget. In the end, that is what matters. You can always trim and tweak.

Since the code button is broken, manually add "

Code: Select all

" before your script, and "[/code}" after. This is all those buttons do, similar to a macro that writes text and places the cursor between those tags. The "quote" button would be handled similarly. I am not sure of the tags.

[quote]I will experiment right now with  etc.[/quote]


Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10331
Joined: Wed May 06, 2009 2:28 pm

Re: 'pasteKey' message

Post by dunbarx » Mon Aug 12, 2013 7:57 pm

OK, so it is the same format, just substitute "quote" for "code"

Craig

Post Reply