DesktopX advice on vbscript

Cannot activate script on mouse down

Could someone please advise me on this script I just cannot get it to run correctly:
Sub Object_OnStateChange(state)
If state = "mouse down" Then
set WshShell = Wscript.Createobject("Wscript.shell")
WshShell.AppActivate "player"
Wscript.Sleep 100
WshShell.sendkeys "{pgdn}"
Wscript.Sleep 100
end if
end sub
Without the if state = line it will work as I pass over the button
but I really need it to work on mouse down.
I want to use it to run the k/b shortcuts on a dvd player.
button is a layer with three states: Mouse away mouse over mouse down
thanks
2,069 views 5 replies
Reply #1 Top

Sub Object_OnLButtonDown(x, y)
set WshShell = Wscript.Createobject("Wscript.shell")
WshShell.AppActivate "player"
Wscript.Sleep 100
WshShell.sendkeys "{pgdn}"
Wscript.Sleep 100
End Sub


Doesn't this Wscript.Createobject("Wscript.shell") give you an error? Does to me. I have to use just Createobject("Wscript.shell")
Reply #2 Top
Same thing with Wscript.Sleep 100, think it should be Sleep 100.

Without the if state = line it will work as I pass over the button
but I really need it to work on mouse down.


Doesn't the Wscript. object give you an error? I tried that my self, but it doesn't seem to be an object accessible in DX scripting.
Reply #3 Top
Just another thought, usually events trigger when the mouse button is released. So the code for executing the code on mouse click would be


Sub Object_OnLButtonUp(x, y, dragged)
If Not dragged Then
'Your code here
End if
End Sub
Reply #4 Top
Firstly thanks for your replies...

And you are correct (Sorry) I should have removed the wscript as it does give an error. Without it I do get funtionality as I originally described. Sorry I posted my "pure" VBscript.

I think I owe you (thomassen) a beer as Object_OnLButtonUp(x,y) has resolved this issue for me. Thanks again.

Just a note that I read a DX tutorial that mentioned that Sleep can cause DesktopX to hang. It recommended using timers instead. I am not sure if this is true but I will keep it in mind just in case.
Reply #5 Top
Yes, the sleep command will halt all operation in your Dx enviroment if I am not incorrect. If you were to keep the existing code with the sleep command, I think you can drop the second sleep command you got there. Can't see that it has any use.

If you go for the timer solution, I think this should work:

Sub Object_OnLButtonUp(x, y, dragged)
If Not dragged Then
Set WshShell = Wscript.Createobject("Wscript.shell")
WshShell.AppActivate "player"
Object.SetTimer 123 100
End If
End Sub

Sub Object_OnTimer123
WshShell.sendkeys "{pgdn}"
Object.KillTimer 123
End Sub


I think I owe you (thomassen) a beer

You know what, yesterday I thought about how nice it would be to work for beer...