Shoutbox

[Help] MS Agent catching clicks - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: [Help] MS Agent catching clicks (/showthread.php?tid=63695)

[Help] MS Agent catching clicks by BstrdSmkr on 07-20-2006 at 09:23 PM

i've read the MS SDK for the agents, which is lacking to say the least : \   the trouble i'm having is trying to catch a click event on the agent. for example, if the user clicks on Merlin when he says something, i want the script to run a function.  any help?


RE: [Help] MS Agent catching clicks by cloudhunter on 07-20-2006 at 10:48 PM

Unfortuneately, it seems like it can't within the scripting system :( As it doesn't register any events apart from the built in one. I've researched it myself, but with no luck.

Cloudy


RE: [Help] MS Agent catching clicks by ddunk on 07-20-2006 at 10:57 PM

Actually, I was researching this a few days back because I wanted to play with the control and I came across

quote:
Programming the Microsoft Agent Control
ActiveX® technology for interactive software agents
Microsoft Corporation
October 1998
A 113 page .doc file explaining everything you did and didn't want to know about the agent control. :P There are a few jscript examples, but it's mostly vbscript.
I'll attach the docs, but here's the click event.
code:
Click Event
Description
Occurs when the user clicks a character or the character’s icon.
Syntax
Sub agent_Click (ByVal CharacterID, ByVal Button, ByVal Shift, ByVal X, ByVal Y)

CharacterID     
Returns the ID of the clicked character as a string.

Button   
Returns an integer that identifies the button that was pressed and released to cause the event. The button argument is a bit field with bits corresponding to the left button (bit 0), right button (bit 1), and middle button (bit 2). These bits correspond to the values 1, 2, and 4, respectively. Only one of the bits is set, indicating the button that caused the event. If the character includes a taskbar icon, and bit 13 is also set, the click occurred on the taskbar icon.

Shift
Returns an integer that corresponds to the state of the SHIFT, CTRL, and ALT keys when the button specified in the button argument is pressed or released. A bit is set if the key is down. The shift argument is a bit field with the least-significant bits corresponding to the SHIFT key (bit 0), the CTRL key (bit 1), and the ALT key (bit 2). These bits correspond to the values 1, 2, and 4, respectively. The shift argument indicates the state of these keys. Some, all, or none of the bits can be set, indicating that some, all, or none of the keys are pressed. For example, if both CTRL and ALT were pressed, the value of shift would be 6.

X,Y
Returns an integer that specifies the current location of the mouse pointer. The X and Y values are always expressed in pixels, relative to the upper left corner of the screen.

Remarks
This event is sent only to the input-active client of a character. When the user clicks a character or its taskbar icon with no input-active client, the server sends the event to its active client. If the character is visible (Visible = True), the user’s action also sets the character’s last input-active client as the current input-active client, sending the ActivateInput event to that client, and then sending the Click event. If the character is hidden (Visible = False), and the user clicks the character’s taskbar icon using button 1, the character is also automatically shown.
Note  Clicking a character does not disable all other character output (all characters). However, pressing the Listening key does flush the input-active character’s output and triggers the RequestComplete event, passing a Request.Status that indicates that the client’s queue was interrupted.

(page 19)

http://ponynugget.net/progagentcontrol.doc

RE: RE: [Help] MS Agent catching clicks by alexp2_ad on 07-20-2006 at 11:01 PM

quote:
Originally posted by cloudhunter
Unfortuneately, it seems like it can't within the scripting system :( As it doesn't register any events apart from the built in one. I've researched it myself, but with no luck.

Cloudy

It can, and here's how.  Add this format for a variable to your code somewhere (outside other functions):

code:
var Clicked = function(){
    function agent::Click(dwCharID,fwKeys,x,y){
        MsgPlus.DisplayToast('Clicked','You clicked Merlin!');
    }
}

Assuming your ActiveXObject("Agent.Control.1") is called "agent".  Then when you declare the agent (eg.  in initialize) add "Clicked();"

Tested and working with that script that made him say what contacts said.  :)


EDIT:  I know this from catching events in iTunes, for iTunes+... was a pain!
RE: [Help] MS Agent catching clicks by cloudhunter on 07-20-2006 at 11:04 PM

Well just shows what a noob I am then ;) Thanks, it's gonna help alot :)

Cloudy


RE: RE: [Help] MS Agent catching clicks by alexp2_ad on 07-20-2006 at 11:06 PM

quote:
Originally posted by cloudhunter
Well just shows what a noob I am then ;)

Oh no, not at all, it's a pain and a very weird way of declaring events, but it seems to be how you declare events for objects.  I only know it because I needed to catch iTunes events...
RE: [Help] MS Agent catching clicks by cloudhunter on 07-20-2006 at 11:13 PM

Well I saw that method of detecting the event done while I was searching the web... I just didn't understand it ;) I knew there must be a way to do it, as when you released a new version of your script, you said youd switched from timers to events.

Thanks for the information :)

Cloudy


RE: [Help] MS Agent catching clicks by deAd on 07-20-2006 at 11:14 PM

Well the JScript parser loads events/functions before variables and stuff, so if you don't use a wrapper it tells you the object is not defined. -dt- posted how to wrap it in some other thread...


RE: [Help] MS Agent catching clicks by BstrdSmkr on 07-21-2006 at 03:30 PM

quote:
Originally posted by alexp2_ad


code:
var Clicked = function(){
    function agent::Click(dwCharID,fwKeys,x,y){
        MsgPlus.DisplayToast('Clicked','You clicked Merlin!');
    }
}



i saw this and others similar to it when i was researching it, but i don't understand it. i understand your post and how to implement your solution, but i'm wondering if you could expand a bit about how this works?  once i've got my head around it, i'll put it all together and post it in "noob-format" for everyone to see lol.

also to clarify:   dwCharID is the name of the agent (merlin, peedy, etc)   
fwKeys is the state of the shift key (boolean)
X and Y are the coords of the pointer when the event occoured.

this is what i gathered between here and my research.  is this correct?

RE: [Help] MS Agent catching clicks by alexp2_ad on 07-21-2006 at 03:40 PM

deAd sort of explained why this works.

The thing is, the JScript parser that runs the code will create the functions and event functions before it makes the objects and does the rest of the code, so when it sees "function agent::Click"  (ie.  the event "Click" for the object "agent") it hasn't made the agent object, so it would complain that it is undefined.  However, if you put the function inside a variable, it's ignored and the event function isn't defined until you call the variable.  (The "Clicked();" bit)  And when you call the variable, it should be after the agent object is made, so it will understand it and not say it's undefined.

And according to the agent documentation those variables are what you said, yeah.  Though I don't think fwKeys is just the shift key, I think it has numbers to represent other keys like ctrl and such.  Can't remember where I saw that now though.


RE: [Help] MS Agent catching clicks by BstrdSmkr on 07-21-2006 at 05:08 PM

so to use it, it would be something like:

code:
agent.Clicked()
{
   doSomethingUseful;
}


or am i reading this wrong? : \
RE: [Help] MS Agent catching clicks by deAd on 07-21-2006 at 05:52 PM

Nope!

code:
var Clicked = function(){
    function agent::Click(dwCharID,fwKeys,x,y){
        //do something useful
    }
}
and somewhere else in the code (probably where you intialize the character:
code:
Clicked();

RE: [Help] MS Agent catching clicks by BstrdSmkr on 07-22-2006 at 02:53 PM

ah ok, got it now.  after messing around with it last night, these are the events that can be defined in a similar manner:

Command-- Occurs when the server processes a client-defined command.
ActivateInputState-- Occurs when a character becomes or ceases to be input-active.
VisibleState-- Occurs when the character's Visible state changes.
Click-- Occurs when a character is clicked.
DblClick-- Occurs when a character is double-clicked.
DragStart-- Occurs when a user starts dragging a character.
DragComplete-- Occurs when a user stops dragging a character. 
RequestStart-- Occurs when the server begins processing a Request object.
Request-- Complete Occurs when the server completes processing a Request object.
Bookmark-- Occurs when the server processes a bookmark.
Idle-- Occurs when the server starts or ends idle processing.
Move-- Occurs when a character has been moved.
Size-- Occurs when a character has been resized.
BalloonVisibleState-- Occurs when the visibility state of a character's word balloon changes.

once i feel comfortable with it, i'll post a how to in the Tips thread :D