473,324 Members | 2,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Hot Key in VB2005?

Hey,
does any one know about using hot keys in a 2005 app?
I posted a similar question in VB but was probably in the wrong forum. I want to be able to send text to a comport if a certain key is held for 2 seconds. I can get this to work with the app in focus but i would like it to work from the back ground as well. I would appreciate a push in the right direction, not looking for anyone to do my code for me. Thanks


Expand|Select|Wrap|Line Numbers
  1. Public Class frmKeyCatcher
  2. Dim WithEvents serialPort As New IO.Ports.SerialPort
  3.  
  4. Private Sub DataReceived( _
  5. ByVal sender As Object, _
  6. ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _
  7. Handles serialPort.DataReceived
  8.  
  9. txtDataReceived.Invoke(New myDelegate(AddressOf updateTextBox), _
  10. New Object() {})
  11. End Sub
  12.  
  13. Public Delegate Sub myDelegate()
  14. Public Sub updateTextBox()
  15. With txtDataReceived
  16. .SelectionColor = Color.Red
  17. .AppendText(serialPort.ReadExisting)
  18. .ScrollToCaret()
  19. End With
  20. End Sub
  21.  
  22. Private Sub frmKeyCatcher_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
  23. serialPort.Close()
  24. End Sub
  25.  
  26.  
  27. Private Sub frmKeyCatcher_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
  28. If e.KeyCode = 49 Then
  29. Timer1.Start()
  30.  
  31. End If
  32. End Sub
  33.  
  34. Private Sub frmKeyCatcher_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
  35. If e.KeyCode = 49 Then
  36. Timer1.Stop()
  37. End If
  38. End Sub
  39.  
  40. Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  41. Me.Show()
  42. Me.BackColor = Color.LightGray
  43. If serialPort.IsOpen Then
  44. serialPort.Close()
  45. End If
  46. Try
  47. With serialPort
  48. .PortName = "COM3"
  49. .BaudRate = 9600
  50. .Parity = IO.Ports.Parity.None
  51. .DataBits = 8
  52. .StopBits = IO.Ports.StopBits.One
  53.  
  54. End With
  55.  
  56. serialPort.Open()
  57. Timer4.Start()
  58. Catch ex As Exception
  59. MsgBox(ex.ToString)
  60. End Try
  61.  
  62. End Sub
  63.  
  64. Private Sub Timer2_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer2.Tick
  65. Me.Hide()
  66. Timer2.Stop()
  67. End Sub
  68.  
  69. Private Sub Timer4_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer4.Tick
  70. Try
  71. serialPort.Write("C")
  72. With txtDataReceived
  73. .SelectionColor = Color.Black
  74. .AppendText("C" & vbCrLf)
  75. .ScrollToCaret()
  76.  
  77. End With
  78. Me.BackColor = Color.white
  79. Catch ex As Exception
  80.  
  81. End Try
  82. Timer4.Stop()
  83. Timer2.Start()
  84. End Sub
  85.  
  86.  
  87. End Class
  88.  
Aug 27 '07 #1
1 1062
Plater
7,872 Expert 4TB
Look up global hooks.
As for an example I like this:
http://www.codeproject.com/csharp/globalhook.asp

It works just like your normal keypresses only it works for when you application is not active as well
Aug 27 '07 #2

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

Similar topics

5
by: Chris Devol | last post by:
My dial-up connection sometimes hangs up and has to re-connect. The VB2005 installer/downloader apparently doesn't know how to resume when the connection is re-established. It just aborts! I've...
3
by: Diarmuid | last post by:
I have the MS book, introducing Microsoft Visual Basic 2005 for Developers. No sample code comes with it.The location according to the book is http://msdn.microsoft.com/vbasic/VB6Migration but I...
2
by: Jerry Spence1 | last post by:
1. Is there a more suitable, dedicated newsfeed for VB2005 yet? 2. I'm confused as to which version to get. I work for a small company and we will just need VB2005 on my PC. Therefore that tends...
1
by: Galen Somerville | last post by:
I uninstalled and reinstalled VB6. When I have an unhandled exception in VB6, it uses the VB2005 Pro debugger. There is no way to leave the VB2005 debugger without ending up at the desktop. How...
0
by: Rich | last post by:
Hello, I just upgraded a vb2003 app to vb2005. The vb2003 app had/has a statusbar object - which contains panels and I can see the properties of the statusbar in the properties window in...
2
by: Omar Abid | last post by:
Hi, This the best site where you can find Hi members, We are happy to tell that if you search for : jobs with high wage or to debug a program or to find a good source code and to make a good...
1
by: erickwan88 | last post by:
I am doing a final year project for my school and is going to provide for an organization, so I am asking for some help on here. Indeed, I have no idea on how to get the input from my pen driver...
15
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...
1
by: Jeffrey Christiansen | last post by:
I wanted to add a toggle button to a VB2005 form to be used for a simple Windows Application (i.e. compiled to a "*.exe"), so I added the ActiveX Microsoft Forms Object toggle button, however I...
1
by: Vae07 | last post by:
Ok so here is a brief summary of my problem. I need a pop up form that submits input text box information to a pocket excel workbook upon a command botton click. Text box inputs are checked for...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.