?
Solved

Using keybd_event In Lotus Notes to print landscape

Posted on 2008-11-06
8
Medium Priority
?
2,089 Views
Last Modified: 2013-12-18
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

0
Comment
Question by:lahlf001
7 Comments
 
LVL 63

Expert Comment

by:SysExpert
ID: 22901311
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
 
LVL 46

Accepted Solution

by:
Sjef Bosman earned 2000 total points
ID: 22903048
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
 

Author Comment

by:lahlf001
ID: 22904886
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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 22905056
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
 

Author Comment

by:lahlf001
ID: 22908223
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
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 22909603
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
 
LVL 58

Expert Comment

by:tigermatt
ID: 34830042
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

Featured Post

Eye-catchers on the conference table

Challenge: The i-unit group was not satisfied with the audio quality during remote meetings. They were looking for a portable solution with excellent audio quality for use in their conference room but also at their client’s offices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
For beginners of Lotus Notes user this is important to know about the types of files and their location supported by IBM Notes. Mostly users are unaware about how many file types are created and what their usages are. This Article is fully dedicated…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question