Capture keys at fome level

  • Thread starter Thread starter Muhammad Arif
  • Start date Start date
M

Muhammad Arif

Dear All,
I am working in VB.Net CF with windows CE. I want to capture the keys
at form level not at control. I mean, when ever a key is pressed in
any control, there should be an event which fire having parameter of
this keys code.

Regards,
Arif
 
I have spent a great deal on this, unfortunatly the compact framework
doesn't support pushing key presses to the form that contains the
control as you can on the full framework. To get around this I simply
forced focus back to the main form after each button press and let the
main form process keyboard input.

I hope this helps
 
Yup,

Got it ..... I have done it through ApplicationEx class.

Thank every one!!
Arif
 
Can you please post a little explanation on how you did it?
I'm fighting with the message structure to implement it... can't find it
anywhere in opennetcf namespace! (it's in opennetcf.windows.forms, but seems
i can't use it!)


Thanks!

btw: is there any sample available?

Matteo.
 
Dear Matteo & All others,

******** ENJOY THE FOLLOWING CODE **********

Regards,
Arif

=====================================================================
Option Explicit On

Imports System
Imports System.Windows.Forms
Imports owf = OpenNETCF.Windows.Forms
Imports mwf = Microsoft.WindowsCE.Forms

Public Class myKeyClass Implements owf.IMessageFilter

Overridable Function PreFilterMessage(ByRef m As mwf.Message) As
Boolean Implements owf.IMessageFilter.PreFilterMessage
Try
Dim key As Integer = m.WParam.ToInt32()

Select Case CType(m.Msg, owf.WinMsg)
Case owf.WinMsg.WM_CHAR
Select Case key
Case 9 'TAB key pressed
MsgBox("TAB key pressed")
Return True
Case 13 'ENTER key pressed
MsgBox("ENTER key pressed")
Return True
End Select 'key
End Select 'm.Msg

Return False
Catch ex As Exception
Return False
MsgBox(ex.ToString)
End Try
End Function
End Class


======================= Usage of above class =======================

Option Explicit On

Imports OpenNETCF.Windows.Forms

Public Class AppExTest
Inherits System.Windows.Forms.Form
Private objMyKeyClass As New myKeyClass

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()
ApplicationEx.AddMessageFilter(objMyKeyClass)

'Add any initialization after the InitializeComponent() call

End Sub
#End Region

Public Shared Sub Main()
ApplicationEx.Run(New AppExTest)
End Sub

Private Sub AppExTest_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
TextBox1.Text = ""
TextBox1.Focus()
End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
ApplicationEx.RemoveMessageFilter(objMyKeyClass)
ApplicationEx.Exit()
End Sub
End Class
 
thanks!

Muhammad Arif said:
Dear Matteo & All others,

******** ENJOY THE FOLLOWING CODE **********

Regards,
Arif

=====================================================================
Option Explicit On

Imports System
Imports System.Windows.Forms
Imports owf = OpenNETCF.Windows.Forms
Imports mwf = Microsoft.WindowsCE.Forms

Public Class myKeyClass Implements owf.IMessageFilter

Overridable Function PreFilterMessage(ByRef m As mwf.Message) As
Boolean Implements owf.IMessageFilter.PreFilterMessage
Try
Dim key As Integer = m.WParam.ToInt32()

Select Case CType(m.Msg, owf.WinMsg)
Case owf.WinMsg.WM_CHAR
Select Case key
Case 9 'TAB key pressed
MsgBox("TAB key pressed")
Return True
Case 13 'ENTER key pressed
MsgBox("ENTER key pressed")
Return True
End Select 'key
End Select 'm.Msg

Return False
Catch ex As Exception
Return False
MsgBox(ex.ToString)
End Try
End Function
End Class


======================= Usage of above class =======================

Option Explicit On

Imports OpenNETCF.Windows.Forms

Public Class AppExTest
Inherits System.Windows.Forms.Form
Private objMyKeyClass As New myKeyClass

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()
ApplicationEx.AddMessageFilter(objMyKeyClass)

'Add any initialization after the InitializeComponent() call

End Sub
#End Region

Public Shared Sub Main()
ApplicationEx.Run(New AppExTest)
End Sub

Private Sub AppExTest_Load(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles MyBase.Load
TextBox1.Text = ""
TextBox1.Focus()
End Sub

Private Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
ApplicationEx.RemoveMessageFilter(objMyKeyClass)
ApplicationEx.Exit()
End Sub
End Class

"Matteo Cima" <mdm.list is_the_username @digisoft.it is_the_domain> wrote
 
Back
Top