Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Key Press behind the scenes


Reply
 
Thread Tools Display Modes
  #1  
Old 11-24-2003, 09:46 PM
john8675309's Avatar
john8675309 john8675309 is offline
Centurion
 
Join Date: Jul 2002
Location: Mankato, Minnesota
Posts: 109
Default Key Press behind the scenes


I have a vb program minimized to the systray and I need it to periodically press enter on one of it's forms without disrupting my work. Does anyone have any idea how to do this?

Thanks,
John
__________________
Never Be afraid to try something new remember professionals built the titanic but ametuers built the ark
Reply With Quote
  #2  
Old 11-24-2003, 09:58 PM
Myth's Avatar
Myth Myth is offline
Contributor
 
Join Date: Oct 2003
Location: Under your bed
Posts: 792
Default

Quote:
Originally Posted by john8675309
I have a vb program minimized to the systray and I need it to periodically press enter on one of it's forms without disrupting my work. Does anyone have any idea how to do this?

Thanks,
John




my best guess whad be to use a timer to keep doin it or a series of timers
__________________
Please use [vb][/vb] tags when posting.
Reply With Quote
  #3  
Old 11-24-2003, 10:01 PM
john8675309's Avatar
john8675309 john8675309 is offline
Centurion
 
Join Date: Jul 2002
Location: Mankato, Minnesota
Posts: 109
Default

that was my plan but I am not sure how I can localize an enter to just a specific program. Do you know how to do this?

--John
__________________
Never Be afraid to try something new remember professionals built the titanic but ametuers built the ark
Reply With Quote
  #4  
Old 11-24-2003, 10:05 PM
Myth's Avatar
Myth Myth is offline
Contributor
 
Join Date: Oct 2003
Location: Under your bed
Posts: 792
Default

Quote:
Originally Posted by john8675309
that was my plan but I am not sure how I can localize an enter to just a specific program. Do you know how to do this?

--John



you could just put what you needed to do in a sub, and call the sub, or i think u can simulate a enter pressed, i kno the keyascii = 13. so if u said
Code:
keyascii = 13
im guessing it would do it then again im not sure so dont quote me for it
ahh also forgot to add
try this
SendKeys {ENTER}
__________________
Please use [vb][/vb] tags when posting.
Reply With Quote
  #5  
Old 11-24-2003, 10:08 PM
john8675309's Avatar
john8675309 john8675309 is offline
Centurion
 
Join Date: Jul 2002
Location: Mankato, Minnesota
Posts: 109
Default

I tried the sendkeys {enter} but it presses enter on any application I am in. I can try the key ascii though. in the mean time is there anything else?

--John
__________________
Never Be afraid to try something new remember professionals built the titanic but ametuers built the ark
Reply With Quote
  #6  
Old 11-24-2003, 10:09 PM
Myth's Avatar
Myth Myth is offline
Contributor
 
Join Date: Oct 2003
Location: Under your bed
Posts: 792
Default

Quote:
Originally Posted by john8675309
I tried the sendkeys {enter} but it presses enter on any application I am in. I can try the key ascii though. in the mean time is there anything else?

--John



well this would be an easier way i guess, u can have it maxmize real quick, send enter , then minimize, but thats he lazy way. and ive run out of ideas
__________________
Please use [vb][/vb] tags when posting.
Reply With Quote
  #7  
Old 11-24-2003, 10:22 PM
john8675309's Avatar
john8675309 john8675309 is offline
Centurion
 
Join Date: Jul 2002
Location: Mankato, Minnesota
Posts: 109
Default

I read something about sendinput os that maybe what I am looking for?

--John
__________________
Never Be afraid to try something new remember professionals built the titanic but ametuers built the ark
Reply With Quote
  #8  
Old 11-25-2003, 12:03 AM
A-Dam A-Dam is offline
Junior Contributor
 
Join Date: Nov 2002
Posts: 357
Default

I don't get it.
You want your VB app to get the Enter key? Or do you want the app to send an Enter keystroke as if it were typed at the keyboard (to whatever app is active)?
Usually, you trap a keystroke in your VB program with in a KeyPress or KeyDown event, in which you would do your code. Can't you just do that desired code in a Timer event and not depend on a keystroke?

Just trying to understand so that I can help (maybe)
__________________
It looks like ketchup; it tastes like ketchup; but brother, it ain't ketchup!
Reply With Quote
  #9  
Old 11-25-2003, 02:50 AM
ryan_thian ryan_thian is offline
Newcomer
 
Join Date: Nov 2003
Posts: 11
Default

Quote:
Originally Posted by john8675309
I have a vb program minimized to the systray and I need it to periodically press enter on one of it's forms without disrupting my work. Does anyone have any idea how to do this?

Thanks,
John



hmm... if I do not misunderstand you, you can always create a timer, which will call the subroutine of the Enter button of the form in question.

For example, the Form is named Form1 and the button is cmdEnter.

In your timer, you can have
Form1.cmdEnter_Click

You have to make Public the cmdEnter_Click routine.
__________________
Regards
Ryan
-------------------------------------------
Code-Lock - Secure Software Protection System for Visual Basic, C# and .NET applications http://www.ChosenBytes.com
Reply With Quote
  #10  
Old 11-25-2003, 04:54 PM
john8675309's Avatar
john8675309 john8675309 is offline
Centurion
 
Join Date: Jul 2002
Location: Mankato, Minnesota
Posts: 109
Default

Quote:
Originally Posted by ryan_thian

hmm... if I do not misunderstand you, you can always create a timer, which will call the subroutine of the Enter button of the form in question.

For example, the Form is named Form1 and the button is cmdEnter.

In your timer, you can have
Form1.cmdEnter_Click

You have to make Public the cmdEnter_Click routine.


What I am doing is making a watchguard automatic authentication program. I have a webbrowser control on the form. When the web page loads the submit button on the applet has focus so if I am in the program and hit enter the applet will submit and authenticate me. I would like to have that same routine done every so many hours. So I created a timer and did a sendkeys event every 5 minutes (in the timer). I also made the application avalible to go into the systray. So when the 5 minute mark rolls around it will press enter no matter where I am on my computer. I would like to localize the enter push just to the program. so that it won't disrupt my work.

Side note: it works just fine if my software has focus. if there was a way to make my program get focus every few hours and then return focus where it got it from that would be ok, but I would really like to localize it to just that program so none of what I am doing is disrupted.

Thanks again for all your help
--John
__________________
Never Be afraid to try something new remember professionals built the titanic but ametuers built the ark

Last edited by Deadalus; 11-25-2003 at 05:13 PM. Reason: Fixed tags
Reply With Quote
  #11  
Old 11-25-2003, 06:09 PM
Deadalus Deadalus is offline
Promising Talent

Retired Moderator
* Guru *
 
Join Date: May 2002
Location: Brussels
Posts: 3,601
Default

You can use PostMessage to send a Enter to your application without giving it focus. In this case you'll still need to deminimize it though, otherwise the Enter won't have any effect.

Code:
Option Explicit Private Const WM_KEYDOWN As Long = &H100 Private Const VK_RETURN As Long = &HD Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, _ ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Sub Timer1_Timer() Dim intOldState As Integer intOldState = Me.WindowState If Me.WindowState = vbMinimized Then Me.WindowState = vbNormal DoEvents End If PostMessage hwnd, WM_KEYDOWN, VK_RETURN, &H1 DoEvents Me.WindowState = intOldState End Sub
Edit: Corrected key name. (It worked with vbKeyReturn too though, because it's the same value.)

Last edited by Deadalus; 11-25-2003 at 06:45 PM.
Reply With Quote
  #12  
Old 11-25-2003, 06:37 PM
Volte's Avatar
Volte Volte is offline
Ultimate Contributor

Retired Leader
* Guru *
 
Join Date: Aug 2001
Posts: 5,343
Default

You might be able to use the DOM capabilities of the WebBrowser control to submit the form through code, possibly by manually calling the appropriate 'submit' method in the applet. The DOM can be referenced by using the 'document' property of the WebBrowser, and from there you can access elements on the webpage using the names given to them in HTML.

I've never had experience doing this, but it's food for thought if you feel like doing a little digging.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
any key press of keyboard newneel General 2 03-20-2003 04:30 PM
Implementation of any key of keyboard press newneel General 2 03-07-2003 08:33 AM
Scroll Bars & Sound @ key press sound Ryan Interface and Graphics 2 08-02-2002 01:14 PM
Key Press Xtreme Game Programming 3 06-13-2001 08:41 PM
Key Press nightmaresc General 6 05-28-2001 07:03 PM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->