Get keypress when form not in focus  
Author Message
ItsMe!!!





PostPosted: Visual Basic Express Edition, Get keypress when form not in focus Top

Hi,

I need some code in my program that when F12 is pressed, even when the program is NOT in focus, can stop timer1.

Thanks,

-Josh



Visual Studio Express Editions44  
 
 
Troy Lundin





PostPosted: Visual Basic Express Edition, Get keypress when form not in focus Top

I believe you will need to use an API for that. Maybe GetASyncKeyState. Check it out.


 
 
DMan1





PostPosted: Visual Basic Express Edition, Get keypress when form not in focus Top

Try this thread for starters...

http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=164166&SiteID=1

If that does not work there are several threads here on Keyboard hooking



 
 
ItsMe!!!





PostPosted: Visual Basic Express Edition, Get keypress when form not in focus Top

I've looked many places for codes and they dont work! Many arn't even for VB express. Could someone please just make this little code piece for me because, on this topic of code currently, I am clueless.

-Josh


 
 
Troy Lundin





PostPosted: Visual Basic Express Edition, Get keypress when form not in focus Top

I asked you to check out GetASyncKeyState. Here is the entire Class.

Public Class Form1

<System.Runtime.InteropServices.DllImport("user32")> Private Shared Function GetAsyncKeyState(ByVal vKey As Integer) As Integer
End Function

WithEvents Timer As New System.Windows.Forms.Timer

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Timer.Enabled = True
Timer.Interval = 100
Timer.Start()
End Sub
Private Sub TimerTick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer.Tick
If CBool(GetAsyncKeyState(123)) = True Then Microsoft.VisualBasic.Interaction.MsgBox("F12 was pressed.")
End Sub
End Class

Simple, no


 
 
ItsMe!!!





PostPosted: Visual Basic Express Edition, Get keypress when form not in focus Top

YES!!! FINALLY!

Thanks for your code, I was clueless on this topic and couldn't do it without your help, thanks very much!

Although it took me like an hour to get in into the rest of my code, I got it!

Thanks again,

Josh