In other words, first I manually select text, it might be in Internet Explorer, it might be in an e-mail, or in any application, and then I run a .vbs script the first step of which is to copy the selection regardless of what application happens to be active. Is that possible?
Thanks,
Larry
http://www.autoitscript.com/autoit3/index.php
--
Regards,
Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect
Will this help? Watch for word-wrap.
<html>
<head>
<title>clips.htm</title>
<script type="text/javascript">
function Clip() {
var obj = new ActiveXObject("htmlfile")
var str = obj.parentWindow.clipboardData.getData("text");
alert(str);
}
</script>
</head>
<body>
<input type="button" value="Clipboard" onclick="Clip()">
</body>
</html>
It only works under IE.
"Dave Patrick" <DSPa...@nospam.gmail.com> wrote in message news:us6zaX2...@TK2MSFTNGP06.phx.gbl...
Also, I want this to work in any application, not just IE.
It seems funny that WSH wouldn't have a simple way of replicating the utterly simple step of pressing Ctrl+C.
Larry
"McKirahan" <Ne...@McKirahan.com> wrote in message news:-96dnSc2rdjBl2bZ...@comcast.com...
----------------
Thanks,
Larry
Try this function:
Function GetClipData()
GetClipData =
CreateObject("htmlfile").parentWindow.clipboardData.getData("text")
End Function
Also, I want this to work in any application, not just IE.
It seems funny that WSH wouldn't have a simple way of replicating the
utterly simple step of pressing Ctrl+C.
[snip]
Try this:
WScript.Echo
CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("text")
But beyond that, I'm confused about
what the code is supposed to do. I thought I
had it working but GetClipData doesn't return
text for me no matter what I do. Even if I first try
using SetData, that returns false, nothing has
changed on the Clipboard, and GetData still
returns nothing.
From this MSDN page:
http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/getdata.as
p
it appears the GetData is used only within
the DHTML of a specific webpage, to capture
a selection. Thinking about it, that makes
sense. I can't see even Microsoft being so reckless
as to let IE read *any* selection or have unrestricted
access to Clipboard data. But several people seem
to think that GetData does *something* useful. So
I'm also wondering whether it varies with IE versions.
I've got IE 5.00 in 98SE, but MSDN says that's sufficient.
I think it's by your IE protections settings
IE >> clipboard works ONLY with low protection settings
Set objIE = CreateObject("InternetExplorer.application")
' IE security settings MUST be set on LOW
objIE.Visible = True
objIE.Navigate "http://snipurl.com/index.php"
' objIE.document.parentwindow.clipboardData.SetData"text",""
'objIE.document.parentwindow.clipboardData.SetData"text","http://www.google.it/search?hl=it&q=internetexplorer.applicati
on%2Bclick&btnG=Cerca+con+Google&meta="
WScript.Sleep 2000
Do While objIE.Busy = True
WScript.Sleep 50
Loop
objIE.document.forms.item(0).link.Value="http://www.google.it/search?hl=it&q=internetexplorer.application%2Bclick&btnG=C
erca+con+Google&meta="
objIE.Document.all.item(106).click
WScript.Sleep 2000
GetText = objIE.document.parentwindow.clipboardData.GetData("text")
msgbox GetText
'objIE.document.parentwindow.clipboardData.SetData"text",TextFromHTML
'TextFromHTML = objIE.document.parentwindow.clipboardData.GetData("text")
'msgbox TextFromHTML
' Nella clip adesso hai il testo della pagina voluta e l'avrai anche in google.txt
' objie.quit
--
Fosco
The MSDN page I linked seems to be
saying that, as well: That you can't copy
from a higher security webpage, from
Word, etc. And your example is getting
text from IE that's run within the same script.
The other posts seemed to be suggesting
that GetData would copy the selection of
any active window, as the OP was asking
for. That seemed far fetched but I wanted to
make sure that I'm not missing something. :)
Thanks, but this doesn't make anything happen (except make an empty message box appear).
Walter's version is the same.
I don't know what to do to make it low security settings in IE, or if that's a good idea.
Thanks, all, for your interest.
Larry
"McKirahan" <Ne...@McKirahan.com> wrote in message news:0PedneQK7dcu82HZ...@comcast.com...
It's not a good idea IMHO
use autoit's clip instead
http://www.hiddensoft.com/autoit3/
$bak = ClipGet()
MsgBox(0, "Clipboard contains:", $bak)
ClipPut($bak & "additional text")
MsgBox(0, "Clipboard contains:", ClipGet())
; Autoit has also HotKeySet maybe useful for your job
HotKeySet
--------------------------------------------------------------------------------
Sets a hotkey that calls a user function.
HotKeySet ( "key" [, "function"] )
Parameters
key The key(s) to use as the hotkey. Same format as Send().
function [optional] The name of the function to call when the key is pressed. Leave blank to unset a previous hotkey.
Return Value
Success: Returns 1.
Failure: Returns 0.
Remarks
Up to 64 simultaneous hotkeys per script may be registered.
If two AutoIt scripts set the same HotKeys, you should avoid running those scripts simultaneously. (The second script
cannot capture the hotkey unless the first script terminates or unregisters the key prior to the second script setting
the hotkey.)
A hotkey-press *typically* interrupts the active AutoIt function/statement and runs its user function until it completes
or is interrupted. Exceptions are as follows:
1) If the current function is a "blocking" function, then the key-presses are buffered and execute as soon as the
blocking function completes. MsgBox and FileSelectFolder are examples of blocking functions. Try the behavior of
Shift-Alt-d in the Example.
2) If you have paused the script by clicking on the AutoIt Tray icon, any hotkeys pressed during this paused state are
ignored.
The following hotkeys cannot be set:
Ctrl+Alt+Delete It is reserved by Windows
F12 It is also reserved by Windows, according to its API.
NumPad's Enter Key Instead, use {Enter} which captures both Enter keys on the keyboard.
Win+B,D,E,F,L,M,R,U; and Win+Shift+M These are built-in Windows shortcuts. Note: Win+B and Win+L might only be reserved
on Windows XP and above.
Alt, Ctrl, Shift, Win These are the modifier keys themselves!
Other Any global hotkeys a user has defined using third-party software, any combos of two or more "base keys" such as
'{F1}{F2}', and any keys of the form '{LALT}' or '{ALTDOWN}'.
When you set a hotkey, AutoIt captures the key-press and does not pass it on to the active application, with one
exception: the Lock keys (NumLock, CapsLock, and ScrollLock) still toggle their respective state!
To Send() a key combination which will trigger a HotKeySet() event, either use ControlSend() or unregister the
HotKeySet() event, otherwise, the Send() event may trigger an infinite loop.
; capture and pass along a keypress
HotKeySet("{Esc}", "captureEsc")
Func captureEsc()
; ... can do stuff here
HotKeySet("{Esc}")
Send("{Esc}")
HotKeySet("{Esc}", "captureEsc")
EndFunc
The called function can not be given parameters. They will be ignored.
@HotKeyPressed macro can be used inside the function to handle several keys in the same function.
Related
Send, ControlSend
Example
; Press Esc to terminate script, Pause/Break to "pause"
Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d
;;;; Body of program would go here ;;;;
While 1
Sleep(100)
WEnd
;;;;;;;;
Func TogglePause()
$Paused = NOT $Paused
While $Paused
sleep(100)
ToolTip('Script is "Paused"',0,0)
WEnd
ToolTip("")
EndFunc
Func Terminate()
Exit 0
EndFunc
Func ShowMessage()
MsgBox(4096,"","This is a message.")
EndFunc
--
Fosco
Larry
"Fosco" <fa...@fake.invalid> wrote in message news:z2LLg.3003$K8....@news.edisontel.com...
> use autoit's clip instead
> http://www.hiddensoft.com/autoit3/
Or "very basic"[1] the Windows default keys :
;[1] NOT all programs use Control+c & Control+v
; highlight the text press ESC to copy and F1 to paste
HotKeySet("{Esc}", "Copy")
HotKeySet("{F1}", "Paste")
While 1
Sleep(100)
WEnd
Func Copy()
send("^c")
EndFunc
Func Paste()
send("^v")
EndFunc
--
Fosco
But you can set/use multiple Hotkeyset (copy1 >> copy2 ecc)
--
Fosco
Thanks, but this doesn't make anything happen (except make an empty message
box appear).
Did you allow for word-wrap? It should all be on ONE line.
Here's another way to test it:
open an IE browser and cut-and-paste the following ONE line into the
Address:
vbscript:Alert(CreateObject("htmlfile").ParentWindow.ClipboardData.GetData("
text"))
It should echo back what you last "cut"; i.e. copied to the clipboard.
Of course, you don't need IE to run it in a .vbs script file.
Just save the original ONE line in a .VBS file and run it to echo
"the selection regardless of what application happens to be active.".
[snip]
Thanks all.
Larry
This is all bout
"Larry" <larry32...@att.net> wrote in message news:uvaCxOi0...@TK2MSFTNGP03.phx.gbl...
[snip]
Did you see my post of 09/06/2006 11:25 PM?
Try this more verbose version:
Option Explicit
Dim objCBD
Set objCBD = CreateObject("htmlfile")
Dim strCBD
strCBD = obj.ParentWindow.ClipboardData.GetData("text")
WScript.Echo strCBD
That actually seems to work on my machine.
At least it worked in Notepad. It can only
work where CTRL + C is a copy hotkey, and there
may be security issues in XP, but you can give
it a try. I wrote this with a pause of 5 seconds so
that you have a chance to click a window to make it
active before the SendKeys runs:
Dim sh
WScript.sleep 5000
Set sh = CreateObject("WScript.Shell")
sh.SendKeys "^C"
This seems a bit dubious, though, unless it's
exactly what you need for something specific.
In most cases I'd consider it a very badly
behaved script if it erases my clipboard
when it runs.
Option Explicit
Dim objCBD
Set objCBD = CreateObject("htmlfile")
Dim strCBD
strCBD = objCBD.ParentWindow.ClipboardData.GetData("text")
WScript.Echo strCBD
--
Fosco
But it gives anyway ONLY the actual clip buffer
he wants to copy selected test
--
Fosco
If i recall he will only highlight the text the rest made by script
and this in ANY app that has the focus
--
Fosco
Thanks for your thoughts.
I made a distinction between your "highlight" and his "select".
The original post asked:
"first I manually select text, it might be in Internet Explorer,
it might be in an e-mail, or in any application, and then I run
a .vbs script the first step of which is to copy the selection
regardless of what application happens to be active. "
My thought was that "manually select text" was more than
just highlighting it; that it included copying it to the clipboard.
The pronoun "I" was used rather than my clients/users/etc.
so I took this to mean that only "Larry" needed to know how
the process would work -- which included pressing Ctrl+C.
Basically, I only addressed the issue of retrieving clipboard
text into his WSH application.
An additional clarification:
The original post asked:
"first I manually select text, it might be in Internet Explorer,
it might be in an e-mail, or in any application, and then I run
a .vbs script the first step of which is to copy the selection
regardless of what application happens to be active. "
Yes, he said "copy the selection" but I took this to mean
"copy the selection" was already copied to the clipboard.
Since multiple applications could be open and each could
have some text "highlighted" I didn't think that copying *to*
the clipboard was the issue. I thought that "Larry" wanted
help copying it *from* the clipboard into his WSH application.