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!

Posted: Sep 7, 2007 15:08 by Kine | with 7 comment(s) |
Bookmark and Share

Comments

# re: Powerfull command in Microsoft Dynamics NAV: BEEP

Very interesting I have to try that once...

Friday, September 07, 2007 10:10 PM by Erik P. Ernst

# re: Powerfull command in Microsoft Dynamics NAV: BEEP

Well done, I bet you spent a lot of hours to work that out.

Thanks for sharing.

Saturday, September 08, 2007 6:32 PM by David Singleton

# re: Powerfull command in Microsoft Dynamics NAV: BEEP

Hi,

I'm new in c/al programming.

Can you give me a code sample how to send a keystroke. And which globals or/and locals I need to create.

Thx

Locutus

Monday, December 10, 2007 4:56 PM by Locutus

# re: Powerfull command in Microsoft Dynamics NAV: BEEP

I'd be very interested in some sample code as well if possible (tommyolesen@hotmail.com)

Thanks

Tommy

Friday, December 14, 2007 10:01 PM by Tommu Olesen

# re: Powerfull command in Microsoft Dynamics NAV: BEEP

see e.g.

www.mibuso.com/.../viewtopic.php

www.mibuso.com/.../viewtopic.php

www.mibuso.com/.../viewtopic.php

etc.

You can google for SendKey as well (MSDN on-line help).

Saturday, December 15, 2007 8:43 AM by Kine

# re: Powerfull command in Microsoft Dynamics NAV: BEEP

Just wondering, if you tried a dusty old "YIELD" command before that?

Wednesday, August 06, 2008 3:25 PM by Vytenis Jakas

# re: Powerfull command in Microsoft Dynamics NAV: BEEP

Of course, I tried it... but this is giving control to other programs and working only for 16bit... it means doing something other than I needed. I needed to give control to NAV during processing some code, and this is the main problem, because the "single" (I know, that it is not only one thread in real) threaded application...

Wednesday, August 06, 2008 8:20 PM by Kine

Leave a Comment

(required) 
(required) 
(optional)
(required)