scripts and the clipboard |
Author: |
Message: |
andrey
elite shoutboxer
Posts: 795 Reputation: 48
– / /
Joined: Aug 2004
|
O.P. scripts and the clipboard
First, I'd like to say
HI!!
I'm back...kinda
I'm a noob when it comes to programming and thought that I'll try something easy for a start, but I already noticed that it isn't easy at all...
The (simple) idea was, that when I type a command like "/isi" (stands for Internal Sound Identifier) in the conversation window, to get the Internal Sound Identifier from the clipboard (if it's present) and send the sound to the contact (maybe by sending the ISI prefixed with "/sound ", or is there an easier way?).
well, here's the code I've got so far, for getting the ISI from the clipboard:
(may or may not be complete bs)
code: if (Interop.Call("User32", "OpenClipboard", 0))
{
if (Interop.Call("User32", "IsClipboardFormatAvailable", "CF_TEXT" || "CF_OEMTEXT"))
{
var hClipboardData = Interop.Call("User32", "GetClipboardData", "CF_TEXT");
var pchData = Interop.Call("Kernel32", "GlobalLock", hClipboardData);
var strFromClipboard = pchData;
Debug.Trace(strFromClipboard);
Interop.Call("Kernel32", "GlobalUnlock", hClipboardData);
}
else
{
Debug.Trace("There is no text data on the Clipboard.");
}
Interop.Call("User32", "CloseClipboard");
}
The part with IsClipboardFormatAvailable is probably not useful, because I need to check if it's a Sound Identifier ala #D9586E19B0CB not if there's text
This code should actually check if there is text in the clipboard, then get it from there and display it in the debug window, but it's not working..dunno why and all my other attempts to get it working have failed.
So...any help would be appreciated
Btw, I did this based on the C++ code on http://www.codeproject.com/clipboard/archerclipboard1.asp
This post was edited on 07-11-2006 at 05:34 AM by andrey.
|
|
07-11-2006 05:29 AM |
|
|
J-Thread
Full Member
Posts: 467 Reputation: 8
– / / –
Joined: Jul 2004
|
RE: scripts and the clipboard
The CF_TEXT and CF_OEMTEXT are constants, don't use them as strings:
code: var CF_TEXT = 516; // check these
var CF_OEMTEXT = 7;
if (Interop.Call("User32", "OpenClipboard", 0))
{
if (Interop.Call("User32", "IsClipboardFormatAvailable", CF_TEXT | CF_OEMTEXT))
{
var hClipboardData = Interop.Call("User32", "GetClipboardData", CF_TEXT);
var pchData = Interop.Call("Kernel32", "GlobalLock", hClipboardData);
var strFromClipboard = pchData;
Debug.Trace(strFromClipboard);
Interop.Call("Kernel32", "GlobalUnlock", hClipboardData);
}
else
{
Debug.Trace("There is no text data on the Clipboard.");
}
Interop.Call("User32", "CloseClipboard");
}
Not tested, but should work better
|
|
07-11-2006 07:13 AM |
|
|
segosa
Community's Choice
Posts: 1407 Reputation: 92
Joined: Feb 2003
|
RE: scripts and the clipboard
I'm having a problem SETTING the text in the clipboard: http://shoutbox.menthix.net/showthread.php?tid=62754
Let me know if you get yours working... maybe we have a similar problem.
The previous sentence is false. The following sentence is true.
|
|
07-11-2006 08:21 AM |
|
|
andrey
elite shoutboxer
Posts: 795 Reputation: 48
– / /
Joined: Aug 2004
|
O.P. RE: RE: scripts and the clipboard
quote: Originally posted by J-Thread
The CF_TEXT and CF_OEMTEXT are constants, don't use them as strings:
code: var CF_TEXT = 516; // check these
var CF_OEMTEXT = 7;
if (Interop.Call("User32", "OpenClipboard", 0))
{
if (Interop.Call("User32", "IsClipboardFormatAvailable", CF_TEXT | CF_OEMTEXT))
{
var hClipboardData = Interop.Call("User32", "GetClipboardData", CF_TEXT);
var pchData = Interop.Call("Kernel32", "GlobalLock", hClipboardData);
var strFromClipboard = pchData;
Debug.Trace(strFromClipboard);
Interop.Call("Kernel32", "GlobalUnlock", hClipboardData);
}
else
{
Debug.Trace("There is no text data on the Clipboard.");
}
Interop.Call("User32", "CloseClipboard");
}
Not tested, but should work better
no sorry..still doesn't work for me...
btw, what should i do with the CF_TEXT and CF_OEMTEXT vars and why did you use 516 and 7 ? got it
hmm...any help?
This post was edited on 07-11-2006 at 10:32 PM by andrey.
|
|
07-11-2006 08:01 PM |
|
|
Ezra
Veteran Member
Forgiveness is between them and God
Posts: 1960 Reputation: 31
37 / /
Joined: Mar 2003
|
RE: scripts and the clipboard
I'm thinking a regex could help you with identifying a sounds hash
Something like:
code: /^\#[A-F0-9]{12}$/s
EDIT: Sound hashes are in HEX codes right? so 0 to F ? and 12 characters?
This post was edited on 07-11-2006 at 08:22 PM by Ezra.
|
|
07-11-2006 08:16 PM |
|
|
deAd
Scripting Contest Winner
Posts: 1060 Reputation: 28
– / /
Joined: Jan 2006
|
RE: scripts and the clipboard
@segosa, i got it to copy the first character
Here's how to read from the clipboard (i cant believe i figured this out ):
code: function readClipboard(){
var CF_TEXT = 1;
var CF_OEMTEXT = 7;
var CF_UNICODETEXT = 13;
try {
if (Interop.Call("User32", "OpenClipboard", 0)){
if (Interop.Call("User32", "IsClipboardFormatAvailable", CF_TEXT | CF_OEMTEXT)){
var hClipboardData = Interop.Call("User32", "GetClipboardData", CF_UNICODETEXT);
var pchData = Interop.Call("Kernel32", "GlobalLock", hClipboardData);
var size = Interop.Call('Kernel32','GlobalSize',hClipboardData);
var str = '';
Interop.Call('Kernel32','RtlMoveMemory',str,pchData,size);
Interop.Call("Kernel32", "GlobalUnlock", hClipboardData);
} else {
return false;
}
Interop.Call("User32", "CloseClipboard");
}
} catch(ex) {
Interop.Call("User32", "CloseClipboard");
return false;
}
return str;
}
The function will return the text. It will return false if there are any errors or if the clipboard is empty. Do not remove the try/catch or the clipboard will not unlock and you won't be able to copy or paste anything at all.
This post was edited on 07-11-2006 at 09:07 PM by deAd.
|
|
07-11-2006 08:41 PM |
|
|
|
|