Hello Guest it is March 28, 2024, 05:16:38 PM

Author Topic: SendKeys ???  (Read 5216 times)

0 Members and 1 Guest are viewing this topic.

Offline BR549

*
  •  6,965 6,965
    • View Profile
SendKeys ???
« on: September 01, 2011, 03:12:44 PM »
I am working on a workaround and trying to use SendKeys.

I have to access a plugin, that part works fine and the window pops up.

I need to send 2 things to the window   "1" and "enter".

When I code it out as soon as the plugin is called the CB side goes dead waiting on the plugin window to close. So it is a catch 22 where neither one can respond. IF I close the plugin window then the CB finishes running the code but it is TOO late by then.

ANY ideas ???

(;-) TP

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: SendKeys ???
« Reply #1 on: September 04, 2011, 04:15:22 AM »
Hi Terry

As no one else has come up with anything, I have something but she isn't the prettiest gal in town - but then neither is sendkeys.

It looks like the plugin is blocking - which may be for good reason - who knows? Anyway, the idea is to spawn a thread outside Mach and execute sendkeys from that. In the .m1s fire the .vbs and THEN fire up your plugin - as written, 5 secs later sendkeys will fire. Season to taste.

You'll see the .m1s is coded to call the .vbs in c:\ - you'll probably want to change this to somewehere under c:\Mach3 or whatever.

Assumptions:
You have the windoze scripting host present and enabled.
The plugin dialog sets focus properly and has a tab set (if it's needed).

I thought twice about posting this cos you could do some truly nasty things with it if you feel like being creative - but as ever - if it breaks your PC, your machine or your heart you get to keep the pieces. ;D

Cheers

Ian
« Last Edit: September 04, 2011, 04:24:03 AM by stirling »

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: SendKeys ???
« Reply #2 on: September 04, 2011, 09:32:49 AM »
Thanks Ian, I never been able to get sendkeys to work here. Even just opening notebook and send a simple message fails in the same manner. tried all the code in the CB book AND all that yall have posted as well. Maybe it is Vista?????

Over here we call that warranty the 30/30 warranty(;-) It is guaranteed for 30 feet or 30 seconds which ever comes first AND if it breaks in half YOU get to keep both halves.

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: SendKeys ???
« Reply #3 on: September 04, 2011, 10:07:57 AM »
just tried it on a copy of vista (raided the skip - any amount in there!) and it worked fine here. Try the attached .vbs. No Mach involved. Just copy it to your desktop and double click it and wait a few secs - sorry - you knew that  ;D

Ian

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: SendKeys ???
« Reply #4 on: September 04, 2011, 07:42:52 PM »
oK That worked here it opened notepad and 5 sec later wrote the script.

Let me work with it some tommorrow I thing that will do the trick IF it can get control of the plugin window.

Do you get your "hardware" working ok??? ANy plans for a serial interface??

Thanks Ian, (;-) TP

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: SendKeys ???
« Reply #5 on: September 04, 2011, 08:29:48 PM »
OK I could not wait I had to go out and fire up the machine to test it . I found the problem here I had the properties set wrong on the VBS file and it was opening in notepad instead of RUN with VBS. That fixed it DID gain control over the plugin window and did the update.

I need to do a little cleanup and double check but I think You fixed it.

Thanks Ian, (;-) TP

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: SendKeys ???
« Reply #6 on: September 04, 2011, 09:42:48 PM »
Ian a question,  Is it possible to pass a variable from the M1s script to the VBS script. If so this could save some complexity and simplify the process.

Possible example????

'**M1S Script
Set oShell=CreateObject ("WScript.Shell")
'any preamble code here
Var1 = GetOemdro(123)     ' Set var1 to value of DRO
oShell.run "C:\TP.vbs"
NotifyPlugins(12345)         ' Open Plugin window
Set oShell = Nothing



'**VBS Script
set oShell = WScript.CreateObject("WScript.Shell")
WScript.Sleep 5000 'wait 5 secs then do the sendkeys
oShell.sendkeys "" &VAR1              'Send var1 value
WScript.Sleep 1000
oShell.sendkeys "{ENTER}"

(;-) TP

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: SendKeys ???
« Reply #7 on: September 05, 2011, 03:38:06 AM »
Do you get your "hardware" working ok??? ANy plans for a serial interface??
Yes thanks - works a treat - modbus setup/monitor interface at the moment, looking at direct serial as well.

Ian a question,  Is it possible to pass a variable from the M1s script to the VBS script.
Yes - the simplest way is probably un-named args. Just push command line arguments separated by spaces and pop them with the arguments method.

Code: [Select]
'**M1S Script
Set oShell=CreateObject ("WScript.Shell")
'any preamble code here

oShell.run "C:\TP.vbs " & GetOemdro(123) 'push the value of DRO

NotifyPlugins(12345)         ' Open Plugin window

Set oShell = Nothing


Code: [Select]
'**VBS Script
set oShell = WScript.CreateObject("WScript.Shell")
Set args = WScript.Arguments

WScript.Sleep 5000 'wait 5 secs then do the sendkeys
oShell.sendkeys args.Item(0) 'Send command line args(0) value

WScript.Sleep 1000
oShell.sendkeys "{ENTER}"

Cheers

Ian

Offline BR549

*
  •  6,965 6,965
    • View Profile
Re: SendKeys ???
« Reply #8 on: September 05, 2011, 10:27:31 AM »
Thanks Ian, That worked perfectly.  Now IF I can get Mach to behave during a tool change routine (T1M6)  I am good to go.

(;-) TP

Offline stirling

*
  • *
  •  2,188 2,188
  • UK
    • View Profile
    • www.razordance.co.uk
Re: SendKeys ???
« Reply #9 on: September 05, 2011, 11:57:03 AM »
Cheers

Ian