Re: Computing for Outlook Express in VB.
- From: "Peter Nolan" <nospam@xxxxxxxxxx>
- Date: Wed, 21 Sep 2005 09:26:21 GMT
"Mike Williams" <Mike@xxxxxxxxxxxxxxxxx> wrote in message
news:dgpern$e5d$1@xxxxxxxxxxxxxxxxxxxxxxx
Certainly. The VB Sendkeys function is designed for just such a purpose. It
doesn't work very
well for lots of things though, and I couldn't get it to work properly for
Ctrl S. However, all
is not lost. You can use the keyboard event API to get at the keyboard from
a slightly lower
level, and that works fine. For starters, try the following code. It
obviously needs some more
work, but it will get you started. As it stands it sends CtrlS to whatever
window happens to be
the active window, at the rate of one per minute. Later you will probably
want to change it so
that it detects the current active window and only sends CtrlS if it is an
Outlook Express new
message window. Also, you'll propably want to hide the VB Form, or perhaps
write the code in a
VB project that does not use a Form (in which case you'll need to use the
various API Timer
functions instead of the VB Timer Control). Anyway, paste the following code
into a VB Form
containing a Timer Control and run the program. Then start a new Outlook
Express message and
start writing your text. You should find that Outlook Express saves the
message every minute,
under control of the VB Timer code.
Mike
Option Explicit
Private Const VK_CONTROL = &H11
Private Declare Sub keybd_event Lib "user32" _
(ByVal bVk As Byte, ByVal bScan As Byte, _
ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Sub Form_Load()
Timer1.Interval = 60000 ' approx 1 minute
End Sub
Private Sub Timer1_Timer()
Call keybd_event(VK_CONTROL, 0, 0, 0) ' press Ctrl key
Call keybd_event(Asc("S"), 0, 0, 0) ' press S key
Call keybd_event(Asc("S"), 0, 2, 0) ' press s key
Call keybd_event(VK_CONTROL, 0, 2, 0) ' release Ctrl key
Caption = Val(Caption) + 1
End Sub
> Oops. Slight mistake in the comments in the code I posted. The correct
> version is:
>
> Call keybd_event(VK_CONTROL, 0, 0, 0) ' press Ctrl key
> Call keybd_event(Asc("S"), 0, 0, 0) ' press S key
> Call keybd_event(Asc("S"), 0, 2, 0) ' release S key (I said press before)
> Call keybd_event(VK_CONTROL, 0, 2, 0) ' release Ctrl key
>
> Also, the line "Caption = Val(Caption) + 1" is only there for test
purposes.
> You should of course remove it.
Hello Mike,
Many thanks for this mighty awesome piece of code. I reckoned that I am an
intermediate level VB programmer but if I say this code snippet is beyond my
capabilities then you might insist I downgrade my perceived status.
Let me copy and paste code and get it working and post to this NG to let you
know how I get on but it may take longer or much longer than the blistering
pace you work at.
I'm a humble physicist. I love programming even if I proceed at the speed of
a tortoise.
:)
Peter Nolan.
Dubin.
.
- Follow-Ups:
- Re: Computing for Outlook Express in VB.
- From: Mike Williams
- Re: Computing for Outlook Express in VB.
- References:
- Re: Computing for Outlook Express in VB.
- From: Randy Birch
- Re: Computing for Outlook Express in VB.
- From: Peter Nolan
- Re: Computing for Outlook Express in VB.
- From: Peter Nolan
- Re: Computing for Outlook Express in VB.
- From: Mike Williams
- Re: Computing for Outlook Express in VB.
- From: Mike Williams
- Re: Computing for Outlook Express in VB.
- Prev by Date: Re: need help creating script - deals with readline and arrays
- Next by Date: Re: Computing for Outlook Express in VB.
- Previous by thread: Re: Computing for Outlook Express in VB.
- Next by thread: Re: Computing for Outlook Express in VB.
- Index(es):
Relevant Pages
|