473,808 Members | 2,869 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB2005 maintain focus on hidden app

4 New Member
Good Day,
I have an application that will send text out of a serial port if i hold down the "1" key for 2 seconds. I am currently just turning a chime on and off but want to expand this to the ability to turn my amplifier on/off etc. I want this to be running in the background but to respond at any time by just hitting a certain key. The program works great one time when i execute, but goes into hide and i never see it again. Any suggestions are appreciated.

Public Class frmKeyCatcher
Dim WithEvents serialPort As New IO.Ports.Serial Port

Private Sub DataReceived( _
ByVal sender As Object, _
ByVal e As System.IO.Ports .SerialDataRece ivedEventArgs) _
Handles serialPort.Data Received

txtDataReceived .Invoke(New myDelegate(Addr essOf updateTextBox), _
New Object() {})
End Sub

Public Delegate Sub myDelegate()
Public Sub updateTextBox()
With txtDataReceived
.SelectionColor = Color.Red
.AppendText(ser ialPort.ReadExi sting)
.ScrollToCaret( )
End With
End Sub

Private Sub frmKeyCatcher_F ormClosing(ByVa l sender As Object, ByVal e As System.Windows. Forms.FormClosi ngEventArgs) Handles Me.FormClosing
serialPort.Clos e()
End Sub


Private Sub frmKeyCatcher_K eyDown(ByVal sender As Object, ByVal e As System.Windows. Forms.KeyEventA rgs) Handles Me.KeyDown
If e.KeyCode = 49 Then
Timer1.Start()

End If
End Sub

Private Sub frmKeyCatcher_K eyUp(ByVal sender As Object, ByVal e As System.Windows. Forms.KeyEventA rgs) Handles Me.KeyUp
If e.KeyCode = 49 Then
Timer1.Stop()
End If
End Sub

Private Sub Timer1_Tick(ByV al sender As Object, ByVal e As System.EventArg s) Handles Timer1.Tick
Me.Show()
Me.BackColor = Color.LightGray
If serialPort.IsOp en Then
serialPort.Clos e()
End If
Try
With serialPort
.PortName = "COM3"
.BaudRate = 96000
.Parity = IO.Ports.Parity .None
.DataBits = 8
.StopBits = IO.Ports.StopBi ts.One

End With

serialPort.Open ()
Timer4.Start()
Catch ex As Exception
MsgBox(ex.ToStr ing)
End Try

End Sub

Private Sub Timer2_Tick(ByV al sender As Object, ByVal e As System.EventArg s) Handles Timer2.Tick
Me.Hide()
Timer2.Stop()
End Sub

Private Sub Timer4_Tick(ByV al sender As Object, ByVal e As System.EventArg s) Handles Timer4.Tick
Try
serialPort.Writ e("C")
With txtDataReceived
.SelectionColor = Color.Black
.AppendText("C" & vbCrLf)
.ScrollToCaret( )

End With
Me.BackColor = Color.white
Catch ex As Exception

End Try
Timer4.Stop()
Timer2.Start()
End Sub


End Class
Aug 22 '07 #1
2 1465
Robbie
180 New Member
... I want this to be running in the background but to respond at any time by just hitting a certain key. ...
Hi. The code which you posted does not look like VB6 code...

I have a 'Declare Function' which you can use in VB6. I don't know if you can use it in .NET though, because I'm not really advanced with it.

Expand|Select|Wrap|Line Numbers
  1. Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
You use it by giving it a keycode to check for. It seems to check the keyboard directly, rather than the program having to have focus for it to work. If it gives back -32767, then the key is pressed, otherwise it's not.

So it would be easier to set up a constant of that, e.g.
Expand|Select|Wrap|Line Numbers
  1. Const KeyPressed As Integer = -32767
Then check the function against that constant, e.g. to check if the Space key is being pressed:

if GetAsyncKeyStat e(vbKeySpace) = KeyPressed then
'The key is down
else
'It's not being pressed down
end if

As I said, that's VB6 code, but I hope you can apply it to what you need it for. And I haven't tested, but there is equivalent code in another programming language I'm familiar with, to check the keyboard directly (and I assume this is what this function does), and it works without the program having to have focus.

EDIT: So you'd need to check regularly with a timer or while-doevents-wend loop or such, whether or not the key is currently down.
Aug 22 '07 #2
jontcaz
4 New Member
[quote=Robbie]Hi. The code which you posted does not look like VB6 code...

Hey Robbie, thanks for the reply, i guess i should have posted this in .net forum eh? I will try your ideas in 6 to see if that works.
Aug 23 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
1692
by: PK9 | last post by:
On my page, I want to set the focus to the top of the page (where I have a message in a label) after a button is clicked. How can I use javascript on the server side to set the focus either to a label OR a hidden input field? I do not have any textboxes on the page. The reason I need this is because I have a datagrid with potentially a LOT of records in it. The user can change these records, and click a Save button at the bottom of my...
5
3351
by: Paul E Collins | last post by:
I have a Web form with a number of text boxes. If the user submits the page with some text boxes filled in, those then become plain text (with accompanying <input type="hidden"> fields for when the page is resubmitted) - so the number of text boxes varies. I was using this to focus on the first text box: <body onLoad="document.forms.elements.focus();"> But it doesn't work when the first text box has been removed. In
17
3868
by: Neil Ginsberg | last post by:
OK, this is a stupid thing, but I can't seem to get this to work. I have a form with a subform (in continuous form view). A combo box on the main form has code in the AfterUpdate event which adds a record to the subform (based on the value of the combo box) and requeries the subform control. I want the focus to return to the combo box on the main form when it's done, but I can't get it to do so if the user enters a value and presses Enter...
10
1950
by: Galen Somerville | last post by:
Going from VB6 (RAD) to VB2005 (SAD) The documentation always shows graphics drawing in a paint event like Private Sub Pictcolor_Paint(ByVal sender As Object, ByVal e _ As System.Windows.Forms.PaintEventArgs) Handles PictColor.Paint End Sub But my VB6 program draws to the picturebox PictColor from many different
2
1849
by: Rich | last post by:
Greetings, I observed that in VB2005 the designer generated code is hidden. The initialize code appears to be stored in a different module than the Form's class module. But the form's class module constructor is in the same module as the Form class (obviously). Well, I exposed the constructor, which was originally unexposed. Is there a way to hide it again after exposing it? I don't mean collapse, I mean hide it the way it was...
1
7734
by: zwieback89 | last post by:
Hi, I have a org tree with hierarchical display of employees built using classic asp and vbscript. I also have list of radio buttons for report names. I have 1 select box with dates in it. Then I click on the submit button to view the reports in Crystal. But
15
2031
by: Aalaan | last post by:
I am presently a user of classic vb6 and hang out on those newsgroups. Some of you may be aware that there is a very anti MS and vb2005 feeling there. I have tried to get them to tell me which features of vb2005 are actually worse then vb6 in practice, and forget the philosophy of backward compatibility for a moment. I would now like to hear "the other side". Could *anyone who previously used vb6* (only those pleased; I feel the others...
11
1829
by: sheldonlg | last post by:
I have a problem with not seeing the current focus while in a particular screen in a my app. The focus does not show for a type=text or textarea. I have tried to reproduce this problem in a test application, but have not been successful is doing that. The actual app has a screen which is displayed on a template and the contents are the return from an AJAX call. In that content there is a hidden block. Clicking on a button in the...
5
2272
by: Dave Rado | last post by:
Hi I have been the following code by Freefind to use on my search page: <form action="http://search.freefind.com/find.html" method="get" accept-charset="utf-8" target="_self"> <input type="hidden" name="id" value=""> <input type="hidden" name="pageid" value="r"> <input type="hidden" name="mode" value="all"> <input type="hidden" name="n" value="0">
6
4121
by: buntyindia | last post by:
Hi, I have a page. There is a section 'sidebar' where bulleted text is there. Just after first bullet there is a hidden IFRAME. That go visible on clicking of that bullet text. My problem is with Safari Browser in Mac and WindowsXP. When we press the tab after first bullet link instead of going to next bulleted text the focus goes to the hidden IFRAME. How can I avoid the focus to hidden IFRAME. I tried both visibility:hidden and...
0
9721
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9600
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10631
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10374
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10114
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7651
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3859
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.