Using keybd_event In Lotus Notes to print landscape

I am sending out an email with a report data in a table.  I have a button in the table that the user can click to print the email in landscape mode, where the code also returns the print orientation back to portriat after printing.  I can get the button to print landscape if i remove the keybd_events for the page setup to portriat part, but when I add the page setup event lines after the print line nothing prints.  From watching the keyboard events flash before me it seems like i need to give the print menu time to finish before i send the page setup keyboard event commands.

The code is from a solution to someone's question a while back (don't know the expert that posted, but very helpful), that had a url to here http://www-01.ibm.com/support/docview.wss?rs=0&uid=swg21087073 and I added the page setup change to portriat events.

What am i doing wrong or how do I recode to allow time for the printing box to finish.
(Declaration)
'The code below should be entered as one line:
Declare Sub keybd_event Lib "user32.dll" (Byval bVk As Integer, Byval bScan As Integer, Byval dwFlags As Integer, Byval dwExtraInfo As Integer)
 
Sub Click(Source As Button) 
	keybd_event 18,0,0,0 ' Alt down - start open Print dialog box
	keybd_event 70,0,0,0 ' F down
	keybd_event 70,0,2,0 ' F up
	keybd_event 80,0,0,0 ' P down
	keybd_event 80,0,2,0 ' P up
	keybd_event 18,0,2,0 ' Alt up
	keybd_event 18,0,0,0 ' Alt down - set print range to start on page 2
	keybd_event 70,0,0,0 ' F down
	keybd_event 70,0,2,0 ' F up
	keybd_event 18,0,2,0 ' Alt up
	keybd_event 9,0,0,0 ' tab down
	keybd_event 9,0,2,0 ' tab up
	keybd_event 50,0,0,0 ' 2 down
	keybd_event 50,0,2,0 ' 2 up - set print range complete
	keybd_event 16,0,0,0 ' shift down - start moving to set page orientation
	keybd_event 9,0,0,0 ' tab down
	keybd_event 9,0,2,0 ' tab up
	keybd_event 16,0,2,0 ' shift key up
	keybd_event 16,0,0,0 ' shift down
	keybd_event 9,0,0,0 ' tab down
	keybd_event 9,0,2,0 ' tab up
	keybd_event 16,0,2,0 ' shift key up
	keybd_event 16,0,0,0 ' shift down
	keybd_event 9,0,0,0 ' tab down
	keybd_event 9,0,2,0 ' tab up
	keybd_event 16,0,2,0 ' shift key up
	keybd_event 16,0,0,0 ' shift down
	keybd_event 9,0,0,0 ' tab down
	keybd_event 9,0,2,0 ' tab up
	keybd_event 16,0,2,0 ' shift key up
	keybd_event 16,0,0,0 ' shift down
	keybd_event 9,0,0,0 ' tab down
	keybd_event 9,0,2,0 ' tab up
	keybd_event 16,0,2,0 ' shift key up
	keybd_event 39,0,0,0 ' RightArrow key down
	keybd_event 39,0,2,0 ' RightArrow key up
	keybd_event 18,0,0,0 ' Alt down
	keybd_event 65,0,0,0 ' A key down
	keybd_event 65,0,2,0 ' A key up
	keybd_event 18,0,2,0 ' Alt up
	keybd_event 13,0,0,0 ' enter key down
	keybd_event 13,0,2,0 ' enter key up - press OK - printing started
	keybd_event 18,0,0,0 ' Alt down - start open page setup to set print orientation back to Portrait
	keybd_event 70,0,0,0 ' F down
	keybd_event 70,0,2,0 ' F up
	keybd_event 71,0,0,0 ' G down
	keybd_event 71,0,2,0 ' G up
	keybd_event 18,0,2,0 ' Alt up
	keybd_event 18,0,0,0 ' Alt down
	keybd_event 79,0,0,0 ' O down
	keybd_event 79,0,2,0 ' O up
	keybd_event 18,0,2,0 ' Alt up
	keybd_event 13,0,0,0 ' enter key down
	keybd_event 13,0,2,0 ' enter key up - Page setup complete
End Sub

Open in new window

lahlf001Asked:
Who is Participating?
 
Sjef BosmanConnect With a Mentor Groupware ConsultantCommented:
Your options:

1) use  a decent SendKeys library, e.g. the one from http://www.notesdesign.com/ndhtml/ndsendky.htm; easy to use, easy to maintain, and it has even a sleep function built in!
Example call:
          Call PushKeys("{SLEEP}{TAB}{ENTER}{TAB 6}{ENTER}")

2) use a decent application to generate printable documents, e.g. Word or Symphony, or even Acrobat; there are interfaces available for both, to create a document that looks a lot better than Notes output

3) use a very decent direct output processor like IntelliPrint or NotesToPaper; the latter now even has a Java programming interface, and can create precision documents in PDF and many other formats
There is a drawback: it'll cost you a bundle... but then you have perfection.
0
 
SysExpertCommented:
Add a couple of seconds wait inside perhaps, before doing the print..

You may need to split the call up to before, and after printing.

Also this may be OS and printer dependent.


I hope this helps !

0
 
lahlf001Author Commented:
sjef

Thanks for the options.  I saw the first option before, but didn't think I could use you it because I can't add the library to everyone's mail database.  Options 2 & 3 are out of scope for what I want to accomplish in the time i have to complete.

I think the sleep option is great, I just need to incorporate it into my button code.

Is there a sleep function in the user32.dll?
0
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

 
Sjef BosmanGroupware ConsultantCommented:
Oh dear... I understand. No offence meant, by the way.

About the Sleep-function, see the Designer Help database (it's a standard function, in R6 and up; R5 I don't know):

"Sleep causes a script to pause for at least the number of seconds specified. The script may pause longer.

Syntax
Sleep ( numExpr )
"
0
 
lahlf001Author Commented:
sjef,
I tried the Sleep function (Sleep 5, inserted after line 47 of my originally posted code) and it sleeped first then printed, but it did not do the page setup back to portrait (lines 48 to 59 or my original code)
keybd_event 13,0,2,0 ' enter key up - press OK - printing started
Sleep 5
keybd_event 18,0,0,0 ' Alt down - start open page setup to set print orientation back to Portrait

Open in new window

0
 
Sjef BosmanGroupware ConsultantCommented:
I think you can shorten your code, with about 20%. Instead of Shift-tabbing to the top and then arrow-down, you can use Ctrl-PgDown. But that's beside the point. What I think that happens is that Notes has not the focus for the keyboad events you generate. Notes needs to wait until it has the focus back. How to do this?

Two calls might help: GetFocus and GetForegroundWindow. Maybe this will prove to be sufficient:

    Declare Function GetFocus Lib "User32" Alias "GetFocus" () As Long

In your code, at the start:

    Dim hwnd As Long
    hwnd= GetFocus()

And just after printing is started:

    Dim i As Integer
    Do Until hwnd= GetFocus()
        i= i + 1
        If i>10 Then Exit Sub
        Sleep 1
    Loop

The loop hopes that focus is regained within 10 seconds. If it isn't, too bad for the printer but it won't be reset.

Try this!

http://msdn.microsoft.com/en-us/library/ms646294(VS.85).aspx
0
 
tigermattCommented:
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.