Powerfull command in Microsoft Dynamics NAV: BEEP

Last few weeks I have worked on some project, which needed to use SendKeys to do something with NAV client. During developing this module I hade problem, how to synchronize of calling SendKeys with behaviour of the NAV client. You know, you send keys to the NAV, client is opening some window (form), it took some time, and as result the keys are sent to incorrect window. I tried to use Timer to synchronize it (wait for opening the window etc.), but it didn’t work. The keys still ended in queue of another window that I wanted.

Once, I added BEEP(440,100) command into the timer when I sent the keys to know, when the event was fired and when the keys were sent into queue. And I wonder – the keys ended in correct window! I found out, that when you send some key sequence, which is opening e.g. File Save dialog, you need to wait for the dialog to open to send e.g. keys to “write” the file name into this dialog. And BEEP will help you with that. Because BEEP needs to talk with Operating system, it somehow “give” the control to OS. When you connect this with Timer event, you can do this:

1) Set timer (e.g. each 100ms), enable it

2) When the OnTimer is called first time, send first key sequence, which open the window

3) Call BEEP after sending the keys

4) In next call of OnTimer send second key sequence

5) Call BEEP after sending  the keys

6) repat the steps through all windows and keys you want to send.

7) In last OnTimer, disable the timer

 

Because you used the BEEP command, each new key sequence will end in correct window, because the beep will be called right after all the keys are processed and NAV is free for processing next command. If you use this without BEEP, all keys will be send “to fast” and will be processed in incorrect windows (may be yes, may be no…).

And if you do not want to listen the beep sound, just set the frequency to 1Hz (0Hz is not working, it just skip the command). I found out, that time of the BEEP must be over 10ms, else it will not the effect. But it seems that the value can vary between computers.

I know, that you will be able now to do the cool things with NAV (e.g. automatic version controling :-)) now, when you know how to use BEEP command to synchronize SendKeys with client. 

Take this as result of my research. I do not know exactly why the beep is working like this, but you must know, that IT IS WORKING (for me and my collegues)! 

 (tested on version 4.00SP3 and 5.0)

Have a fun with your new powerfull command BEEP![8-|] [Y]

10 thoughts on “Powerfull command in Microsoft Dynamics NAV: BEEP”

  1. Hi

    …Because BEEP needs to talk with Operating system, it somehow “give” the control to OS..

    But this purposes having a NAV function as YIELD.

  2. Yes, but YIELD was there for old 16bit systems, not working now on 32bit. I tried it, but it is not working with it, with BEEP it is working… :-)

  3. I am happy that it is working for you. And I used it for similar thing as you – Version Control for NAV (automatic txt export of objects for central repository)

  4. Hi

    This thing need for create fob file for send to customer after upgrade objects from old version to new version. This list of objects create from VCC.

    I’m core developer a Version Control (CVC) till first release)))

  5. Hi Kine
    Be careful with the “SendKeys”…

    The SendKeys class has been updated for the .NET Framework 3.0 to enable its use in applications that run on Windows Vista.
    The SendKeys class is susceptible to timing issues, which some developers have had to work around. The updated implementation is still susceptible to timing issues, but is slightly faster and may require changes to the workarounds.

    more here…
    http://msdn2.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>