Discussion:
How do I paste into a different app?
(too old to reply)
Bill Vlahos
2009-12-20 21:32:03 UTC
Permalink
Is there a way to paste text from my stack to the text insertion point of a different program?

I can create a floating window (system window) which floats above all other windows. The idea is that the user would click on a field in the target window (say a password field in a web browser) and then click a button on the floating window that will paste the password into it.

I've tried the "type" and "paste" commands but they don't do anything outside of the stack. Is there a way to remotely issue a paste command or simulate typing?

Thanks,
Bill Vlahos
Bill Vlahos
2009-12-30 22:55:03 UTC
Permalink
It looks like on the Mac you can get AppleScript to send keystrokes by telling the application "System Events".

tell application "System Events"
keystroke "x"
end tell

How can I tell Rev to execute this AppleScript code?

Bill Vlahos
_________________
InfoWallet (http://www.infowallet.com) helps me remember the important details of my life.
Post by Bill Vlahos
Is there a way to paste text from my stack to the text insertion point of a different program?
I can create a floating window (system window) which floats above all other windows. The idea is that the user would click on a field in the target window (say a password field in a web browser) and then click a button on the floating window that will paste the password into it.
I've tried the "type" and "paste" commands but they don't do anything outside of the stack. Is there a way to remotely issue a paste command or simulate typing?
Thanks,
Bill Vlahos
_______________________________________________
use-revolution mailing list
http://lists.runrev.com/mailman/listinfo/use-revolution
Sarah Reichelt
2009-12-30 23:19:00 UTC
Permalink
Post by Bill Vlahos
It looks like on the Mac you can get AppleScript to send keystrokes by telling the application "System Events".
tell application "System Events"
       keystroke "x"
end tell
How can I tell Rev to execute this AppleScript code?
Store that script in a field or custom property, then when you need
it, put it into a variable and use "do as AppleScript".
e.g.

put the cPasteAppleScript of this stack into tScript
do tScript as AppleScript

To emulate a paste command, you will need something like:
keystroke "v" using command down

However you probably want to make sure the correct app is frontmost
before you paste.
So you can use something like this as the first line of your AppleScript:
tell application "TextEdit" to activate

HTH,
Sarah
Bill Vlahos
2009-12-31 15:27:47 UTC
Permalink
Thanks Sarah.

I figured it out and have it working on the Mac with AppleScript. I'm not using a paste function but the AppleScript "keystroke" function. It looks like the Windows API "keybd_event" can do the same type of thing.

I don't really know anything about VBScripting. If I know what the VBScript commands for keybd_event can I do the same thing? How?

Bill
Post by Sarah Reichelt
Post by Bill Vlahos
It looks like on the Mac you can get AppleScript to send keystrokes by telling the application "System Events".
tell application "System Events"
keystroke "x"
end tell
How can I tell Rev to execute this AppleScript code?
Store that script in a field or custom property, then when you need
it, put it into a variable and use "do as AppleScript".
e.g.
put the cPasteAppleScript of this stack into tScript
do tScript as AppleScript
keystroke "v" using command down
However you probably want to make sure the correct app is frontmost
before you paste.
tell application "TextEdit" to activate
HTH,
Sarah
_______________________________________________
use-revolution mailing list
http://lists.runrev.com/mailman/listinfo/use-revolution
Bill Vlahos
2010-01-07 04:47:14 UTC
Permalink
It looks like Microsoft has deprecated the keybd_event API and suggests using SendInput() instead.

Below is a sample of what needs to be sent. This is a C++ example. How do I send this from Rev in Windows? It looks similar to what I do with AppleScript on the Mac? While the send...as applescript commands are documented in Rev's dictionary I don't see anything similar for Windows APIs.

INPUT inp[2];
memset(inp,0,sizeof(INPUT));
inp[0].type = INPUT_KEYBOARD;
inp[0].ki.dwFlags = KEYEVENTF_UNICODE; // to avoid shift, and so on
inp[1] = inp[0];
inp[1].ki.dwFlags |= KEYEVENTF_KEYUP;

for (LPCTSTR p=str; *p; p++) {
inp[0].ki.wScan = inp[1].ki.wScan = *p;
SendInput(2, inp, sizeof(INPUT));
}

Here are some relevant links:
http://msdn.microsoft.com/en-us/magazine/cc163867.aspx
http://www.codeguru.com/forum/showthread.php?t=377393
http://msdn.microsoft.com/en-us/library/ms646310(VS.85).aspx
Post by Bill Vlahos
I figured it out and have it working on the Mac with AppleScript. I'm not using a paste function but the AppleScript "keystroke" function. It looks like the Windows API "keybd_event" can do the same type of thing.
Bill Vlahos
_________________
InfoWallet (http://www.infowallet.com) helps me remember the important details of my life.
Jim Ault
2009-12-30 23:26:10 UTC
Permalink
It may sound simple, but using the system clipboard to move data
between programs automatically is very complex.

The receiving app needs to be the frontmost app, its selection needs
to be compatible with the incoming data, and formatting conversions
may be difficult to control.
One of the inescapable issues is that other programs and the user
employ the system clipboard. As you use the clipboard, the previous
contents are purged, which may not always be OK with the user.


Search for 'applescript' in the Rev archives and you will see many
examples and discussions of scripting.
Do "applescript clipboard system windows" in google and read about
some of the features and how to control them.

Hope this helps

Jim Ault
Las Vegas
Post by Bill Vlahos
It looks like on the Mac you can get AppleScript to send keystrokes
by telling the application "System Events".
tell application "System Events"
keystroke "x"
end tell
How can I tell Rev to execute this AppleScript code?
Bill Vlahos
_________________
InfoWallet (http://www.infowallet.com) helps me remember the
important details of my life.
Post by Bill Vlahos
Is there a way to paste text from my stack to the text insertion
point of a different program?
I can create a floating window (system window) which floats above
all other windows. The idea is that the user would click on a field
in the target window (say a password field in a web browser) and
then click a button on the floating window that will paste the
password into it.
I've tried the "type" and "paste" commands but they don't do
anything outside of the stack. Is there a way to remotely issue a
paste command or simulate typing?
r***@m-r-d.de
2010-01-07 11:02:47 UTC
Permalink
Hi Bill,

i have done something similar. You can create a vbs script and let Rev run this.

I am not very good at VBS, but the following lines show how to insert text into an app.

___________________
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "winword.exe"
'the app is opened. If your app is already running, you do not need this line
WScript.Sleep 2000
'script stops for 2000 milliseconds to take sure, that the app is running before further proceeding.

WshShell.AppActivate "Dokument1 - Microsoft Word"
'activates your already running app
'between the quotes you have to put the exact name of the app - as it is shown in the title bar of that app
' winword also shows the document name in the title bar

WScript.Sleep 100
'script stops for 100 milliseconds'

WshShell.SendKeys "This Text should be inserted"
'the text between the quotes is sent to the app

WScript.Sleep 100
WshShell.SendKeys "{enter}"
'sends an enter to winword
WScript.Sleep 100

WshShell.SendKeys "This Text should also be inserted"
'the text between the quotes is sent to the app

____________________

Maybe Ken Ray could jump in, as he knows much more about VB and VBS.

Regards,

Matthias





-------- Original Message --------
Subject: How to invoke SendInput() Windows API. was Re: How do I paste into a different app? (07-Jan-2010 6:42)
Post by Bill Vlahos
It looks like Microsoft has deprecated the keybd_event API and suggests
using SendInput() instead.
Below is a sample of what needs to be sent. This is a C++ example. How do I
send this from Rev in Windows? It looks similar to what I do with
AppleScript on the Mac? While the send...as applescript commands are
documented in Rev's dictionary I don't see anything similar for Windows
APIs.
INPUT inp[2];
memset(inp,0,sizeof(INPUT));
inp[0].type = INPUT_KEYBOARD;
inp[0].ki.dwFlags = KEYEVENTF_UNICODE; // to avoid shift, and so on
inp[1] = inp[0];
inp[1].ki.dwFlags |= KEYEVENTF_KEYUP;
for (LPCTSTR p=str; *p; p++) {
inp[0].ki.wScan = inp[1].ki.wScan = *p;
SendInput(2, inp, sizeof(INPUT));
}
http://msdn.microsoft.com/en-us/magazine/cc163867.aspx
http://www.codeguru.com/forum/showthread.php?t=377393
http://msdn.microsoft.com/en-us/library/ms646310(VS.85).aspx
Post by Bill Vlahos
I figured it out and have it working on the Mac with AppleScript. I'm not
using a paste function but the AppleScript "keystroke" function. It looks
like the Windows API "keybd_event" can do the same type of thing.
Bill Vlahos
_________________
InfoWallet (http://www.infowallet.com) helps me remember the important
details of my life.
_______________________________________________
use-revolution mailing list
Please visit this url to subscribe, unsubscribe and manage your
http://lists.runrev.com/mailman/listinfo/use-revolution
Bill Vlahos
2010-03-08 06:25:03 UTC
Permalink
I found this on Microsoft's developer site but I don't know how I can implement it.
The SendKeys class has been updated for the .NET Framework 3.0 to enable its use in applications that run on Windows Vista. The enhanced security of Windows Vista (known as User Account Control or UAC) prevents the previous implementation from working as expected.
The SendKeys class is susceptible to timing issues, which some developers have had to work around. The updated implementation is still susceptible to timing issues, but is slightly faster and may require changes to the workarounds. The SendKeys class tries to use the previous implementation first, and if that fails, uses the new implementation. As a result, the SendKeys class may behave differently on different operating systems. Additionally, when the SendKeys class uses the new implementation, the SendWaitmethod will not wait for messages to be processed when they are sent to another process.
If your application relies on consistent behavior regardless of the operating system, you can force the SendKeys class to use the new implementation by adding the following application setting to your app.config file.
<appSettings>
<add key="SendKeys" value="SendInput"/>
</appSettings>
To force the SendKeys class to use the previous implementation, use the value "JournalHook" instead.
Bill Vlahos
_________________
InfoWallet (http://www.infowallet.com) is about keeping your important life information with you, accessible, and secure.
Hi Bill,
i have done something similar. You can create a vbs script and let Rev run this.
I am not very good at VBS, but the following lines show how to insert text into an app.
___________________
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "winword.exe"
'the app is opened. If your app is already running, you do not need this line
WScript.Sleep 2000
'script stops for 2000 milliseconds to take sure, that the app is running before further proceeding.
WshShell.AppActivate "Dokument1 - Microsoft Word"
'activates your already running app
'between the quotes you have to put the exact name of the app - as it is shown in the title bar of that app
' winword also shows the document name in the title bar
WScript.Sleep 100
'script stops for 100 milliseconds'
WshShell.SendKeys "This Text should be inserted"
'the text between the quotes is sent to the app
WScript.Sleep 100
WshShell.SendKeys "{enter}"
'sends an enter to winword
WScript.Sleep 100
WshShell.SendKeys "This Text should also be inserted"
'the text between the quotes is sent to the app
____________________
Maybe Ken Ray could jump in, as he knows much more about VB and VBS.
Regards,
Matthias
-------- Original Message --------
Subject: How to invoke SendInput() Windows API. was Re: How do I paste into a different app? (07-Jan-2010 6:42)
Post by Bill Vlahos
It looks like Microsoft has deprecated the keybd_event API and suggests
using SendInput() instead.
Below is a sample of what needs to be sent. This is a C++ example. How do I
send this from Rev in Windows? It looks similar to what I do with
AppleScript on the Mac? While the send...as applescript commands are
documented in Rev's dictionary I don't see anything similar for Windows
APIs.
INPUT inp[2];
memset(inp,0,sizeof(INPUT));
inp[0].type = INPUT_KEYBOARD;
inp[0].ki.dwFlags = KEYEVENTF_UNICODE; // to avoid shift, and so on
inp[1] = inp[0];
inp[1].ki.dwFlags |= KEYEVENTF_KEYUP;
for (LPCTSTR p=str; *p; p++) {
inp[0].ki.wScan = inp[1].ki.wScan = *p;
SendInput(2, inp, sizeof(INPUT));
}
http://msdn.microsoft.com/en-us/magazine/cc163867.aspx
http://www.codeguru.com/forum/showthread.php?t=377393
http://msdn.microsoft.com/en-us/library/ms646310(VS.85).aspx
Post by Bill Vlahos
I figured it out and have it working on the Mac with AppleScript. I'm not
using a paste function but the AppleScript "keystroke" function. It looks
like the Windows API "keybd_event" can do the same type of thing.
Bill Vlahos
_________________
InfoWallet (http://www.infowallet.com) helps me remember the important
details of my life.
_______________________________________________
use-revolution mailing list
Please visit this url to subscribe, unsubscribe and manage your
http://lists.runrev.com/mailman/listinfo/use-revolution
_______________________________________________
use-revolution mailing list
http://lists.runrev.com/mailman/listinfo/use-revolution
Continue reading on narkive:
Loading...