Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

MYOB software automation


  • Please log in to reply
10 replies to this topic
PicantePeperoni
  • Members
  • 5 posts
  • Last active: Nov 02 2010 09:33 PM
  • Joined: 01 Nov 2010
Hello AutoHotkey gurus,
I've been automating tasks for a few months now and I've come into a problem early on that I still have not been able to solve. I want to automate the input of information into an accounting software called MYOB (mind your own business). The autohotkey script works fine when accessing the system and programs other than the MYOB software but once the autohotkey script activates the MYOB window all control is lost. By control I mean that sending keystrokes results in nothing. Even if I set F1 to start a new script and press the F1 key when MYOB is activated, the MYOB software opens the help section instead of running the script.

My question is, does MYOB have an old interface that locks to the physical keyboard and mouse which prevents any logical input from autohotkey? Possibly this is a security feature? The software is very basic and I feel that this is a legacy issue and not a security issue. Has anyone seen this before or found a solution to this problem?

I've tried searching google for a solution but I seems that no-one has had this issue and no-one has tried automating the myob software. I also have tried all sorts of "Send" such as send event and send play but nothing gets a response.

Thanks for your help,
Picante

letmein123
  • Members
  • 101 posts
  • Last active: Feb 17 2012 11:56 PM
  • Joined: 18 May 2010
im not sure if this helps but whenever i had problems with a program not accepting the send command for text, i could usually use CTRL + V to get around it.

So in order to use it, i assign the text to the variable Clipboard and then when i send the CTRL + V command, it will send whatever is in clipboard.

OceanMachine
  • Members
  • 790 posts
  • Last active: Aug 23 2013 02:10 PM
  • Joined: 15 Oct 2007
Hi,

Could you post some example code please, so we can see what you are attempting?

You could also try using #UseHook to see if that makes a difference for you:
#UseHook
F1::MsgBox, Hi

Or alternatively use the $ prefix on all your hotkeys that you want to use with this program.

Please note: if you are using Win95/98Me, then the above will not work:

The keyboard hook is not supported under Windows 95/98/Me because those operating systems require a different type of hook that must reside in a DLL file.



  • Guests
  • Last active:
  • Joined: --
Thanks for all of the input but my problem still exists.

I have tried the #usehook and the #installkeyboardhook (though they are the same) which makes the key work great when MYOB is not activated but anytime that the program becomes activated the native key takes over and the F1 key will bring up the help rather than displaying the msg box.

The code I am using is exactly as OceanMachine supplied. Ive also tried to send a keystroke F1 with the send command but the send command will not be triggered until I am able to trigger the script with a hotkey.

Thanks again for your help,
-Picante

PicantePeperoni
  • Members
  • 5 posts
  • Last active: Nov 02 2010 09:33 PM
  • Joined: 01 Nov 2010
Sorry that last post was mine.

Looking again at Ocean Machine's post it may be possible that the program is using a ME type of interface, though I am using win7.

Does anyone know of a way to get around this, can I can test it?


-Picante

OceanMachine
  • Members
  • 790 posts
  • Last active: Aug 23 2013 02:10 PM
  • Joined: 15 Oct 2007
Hi,

So, you still didn't post any code. Let me clarify something:
1) You run an AHK script that contains my code (and nothing else), and press F1 (physically), you get a MsgBox saying "Hi", right?
2) when you then physically activate the MYOB window and physically press the F1 key on your keyboard, you don't get a MsgBox, and the help application for MYOB appears? Is that correct?

If the above is not what is happening, then you will need to clarify exactly what is happening (or not happening and what you expect should happen), and try to provide the code that goes along with the problem.

HTH.

PicantePeperoni
  • Members
  • 5 posts
  • Last active: Nov 02 2010 09:33 PM
  • Joined: 01 Nov 2010
That is exactly what is happening. Sorry for the confusion.

#NoEnv
#UseHook

$F1::MsgBox, Hi
Return

Esc::ExitApp

Even the Esc key does not work within MYOB for autohotkey. It only uses its native function within the program.

Please let me know if you would like me to clarify anything else.

-Picante

OceanMachine
  • Members
  • 790 posts
  • Last active: Aug 23 2013 02:10 PM
  • Joined: 15 Oct 2007
Hmm, OK, can you try the below code please? It should trigger something when you release the F1 key after pressing it:
(based on some code posted by Sean here)

#NoEnv
   #Persistent
   OnExit, Unhook

   ; this will call the below callback function when a keyboard event is received
   hHookKeybd := SetWindowsHookEx(WH_KEYBOARD_LL   := 13, RegisterCallback("Keyboard", "Fast"))
Return ; end auto execute section

; ======================================

Unhook:
   UnhookWindowsHookEx(hHookKeybd) ; gracefully release the hook when the script exits
ExitApp

Keyboard(nCode, wParam, lParam)
{
   Critical
   If !nCode ; if this var contains some info about a keyboard event, then process it
   {
      vkCode := NumGet(lParam+0, 0)
      scanCode := NumGet(lParam+0, 4)

      If ( scanCode = 59 ) ; 59 = 0x3b = F1 key scan code
      {
         If ( wParam = 257 ) ; 257 = 0x0101 = WM_KEYUP message
            SetTimer, DoStuff, 50 ; allow func to return then trigger what we want

         Return -1 ; indicate that we processed this message amd dont want anything else in the hook chain to recieve it
      }
   }

   Return CallNextHookEx(nCode, wParam, lParam) ; make sure other hooks in the chain receive this event if we didn't process it
}


SetWindowsHookEx(idHook, pfn)
{
   Return DllCall("SetWindowsHookEx", "int", idHook, "Uint", pfn, "Uint", DllCall("GetModuleHandle", "Uint", 0), "Uint", 0)
}

UnhookWindowsHookEx(hHook)
{
   Return DllCall("UnhookWindowsHookEx", "Uint", hHook)
}

CallNextHookEx(nCode, wParam, lParam, hHook = 0)
{
   Return DllCall("CallNextHookEx", "Uint", hHook, "int", nCode, "Uint", wParam, "Uint", lParam)
}

DoStuff:
   SetTimer, DoStuff, Off ; important otherwise the below code will keep repeating.
   ; ....
   MsgBox, Hi from AHK Script - do some stuff here
   ; ...
Return


PicantePeperoni
  • Members
  • 5 posts
  • Last active: Nov 02 2010 09:33 PM
  • Joined: 01 Nov 2010
Wow! that gets me very close!

So after running the code you have provided I can see that the key is now functioning properly except that it still opens a webpage for help. It seems that the keys are doubled.

With no script running and I press the F1 key the software opens two webpages for help. This is as if the button was pressed twice. I have noticed this behavior before when I would click an object and it would then click again. this does not happen all of the time for clicking but happens every time for the F1 key.

When I run your script I get only a single webpage that opens the help and I also get the message box indicating that autohotkey is working perfectly. It seems that the F1 key has been hooked to autohotkey and the second time the F1 key is "pressed" it operates normally.

So, to understand a little better, this script is intercepting the keystrokes in a different way than autohotkey's default mechanism. I can see that it is interfacing with a DLL that seems to be currently loaded and probably has to do with the program that is currently activated.
Are there any advantages or disadvantages to using this mechanism instead of the default?
Also, Is there any way to make it callable instead of integrated into my script?( to call "myHookEventManager(F1)" which would set F1 to hook properly)

Thank you so much for your help, never could have gotten this far without you,
-Picante :D

OceanMachine
  • Members
  • 790 posts
  • Last active: Aug 23 2013 02:10 PM
  • Joined: 15 Oct 2007
OK, so that means that 2 events are being fired for some reason, one of which is not being caught by the AHK hook, and is passing through to the other window.

Try the below (which should pop up a message box when any key is pressed, however we are only interested what happens when you press F1). If you get the messagebox that appears with all the extra info in, could you hit CTRL-C on the mesage box and paste it in here please?

#NoEnv
   #Persistent
   OnExit, Unhook

   ; this will call the below callback function when a keyboard event is received
   hHookKeybd := SetWindowsHookEx(WH_KEYBOARD_LL   := 13, RegisterCallback("Keyboard", "Fast"))
Return ; end auto execute section

; ======================================

Unhook:
   UnhookWindowsHookEx(hHookKeybd) ; gracefully release the hook when the script exits
ExitApp

Keyboard(nCode, wParam, lParam)
{
   Critical
   If !nCode ; if this var contains some info about a keyboard event, then process it
   {
      vkCode := NumGet(lParam+0, 0)
      scanCode := NumGet(lParam+0, 4)

      If ( scanCode = 59 ) ; 59 = 0x3b = F1 key scan code
      {
         If ( wParam = 257 ) ; 257 = 0x0101 = WM_KEYUP message
            SetTimer, DoStuff, 50 ; allow func to return then trigger what we want

         Return -1 ; indicate that we processed this message amd dont want anything else in the hook chain to recieve it
      }
      [color=red]Else
      {
         MsgBox, % "Something other than F1 (scanCode 59) seems to have been pressed...`nwParam: " . wParam . "`nscanCode: " . scanCode . "`nvkCode: " . vkCode . "`nExtended: " . NumGet(lParam+0, 8) & 1 . "`nTime: " . NumGet(lParam+0, 12)
      }[/color]
   }

   Return CallNextHookEx(nCode, wParam, lParam) ; make sure other hooks in the chain receive this event if we didn't process it
}


SetWindowsHookEx(idHook, pfn)
{
   Return DllCall("SetWindowsHookEx", "int", idHook, "Uint", pfn, "Uint", DllCall("GetModuleHandle", "Uint", 0), "Uint", 0)
}

UnhookWindowsHookEx(hHook)
{
   Return DllCall("UnhookWindowsHookEx", "Uint", hHook)
}

CallNextHookEx(nCode, wParam, lParam, hHook = 0)
{
   Return DllCall("CallNextHookEx", "Uint", hHook, "int", nCode, "Uint", wParam, "Uint", lParam)
}

DoStuff:
   SetTimer, DoStuff, Off ; important otherwise the below code will keep repeating.
   ; ....
   MsgBox, Hi from AHK Script - do some stuff here
   ; ...
Return


PicantePeperoni
  • Members
  • 5 posts
  • Last active: Nov 02 2010 09:33 PM
  • Joined: 01 Nov 2010
So now when I run the script withing the MYOB software I don't get a message box as before. It still runs the help in the background. If I press the F1 key and then hit another, such as Esc, within a quick succession then I get the screenshot below and any button afterwards will continue to display the msgbox. If I only press the F1 key and wait I can still use any key I want without having the msgbox appear.

Posted Image

Couldn't get a direct copy from the window so I thought I would provide a screen shot.

Since this is not displaying the information after pressing the F1 key alone I feel the screenshot is not very helpful because it is the result of my interaction and not the program MYOB.

-Picante