Capture Keys needed urgently

  • Thread starter Thread starter Dharth
  • Start date Start date
D

Dharth

Hi,
I'm developping an application to input data in a ppc using c#.
It's absolutely necesary to use TAB key (or some thing similar) to
pass focus from one control to another because users can only have one
free hand to work.

I've read in many messages to use a dll hook made in c/c++ imported in
c# and used it.
Does anyone have this DLL and could send it to me?
Does any one have a little project with this hook DLL that simply pass
the focus from a textbox to a Combo and then to a Button in c#/VB.NET?

thanks in advance,

Dharth
 
It's not a simple task that someone can just "send you a file" to fix. You
need to have a hook DLL that passes messages to a function *you must write*
in your app that then handles moving focus as you deem fit.
 
I've implemented this functionality in a completely managed way, i.e. not
using any unmanaged DLLs, etc.

First of all, create a custom class that inherits from TextBox; the only
addition you need to make is adding a public member that holds an array
index:

Private Class MyTextBox : Inherits TextBox
Public ArrayIndex As Integer
End Class

Secondly, you need to create an array of type MyTextBox, and then populate
the array with new MyTextBoxes; give each MyTextBox a new ArrayIndex. Also,
add an event handler for each, for the OnKeyPress event.

Private m_MyTextBoxes(nNumMyTextBoxes - 1) As MyTextBox

For nI = 0 To nNumMyTextBoxes - 1
m_MyTextBoxes(nI) = New MyTextBox()
m_MyTextBoxes(nI).ArrayIndex = nI
m_MyTextBoxes(nI).Parent = MyForm
m_MyTextBoxes(nI).Bounds = (x, y, width, height)
AddHandler m_MyTextBoxes(nI).KeyDown, AddressOf MyOnKeyDownHandler
Next

Finally, you can capture a key press from within the MyTextBox's OnKeyDown
event handler. You can determine if it was the Tab key, get the current
MyTextBox's ArrayIndex, then set the focus to the next MyTextBox.

Private Sub MyOnKeyDownHandler(ByVal sender As Object, ByVal e As
KeyEventArgs)
If e.KeyCode.Equals(Keys.Tab) Then
nCurrIndex = CType(sender, MyTextBox).ArrayIndex
m_MyTextBoxes(nCurrIndex + 1).Focus()
End If
End Sub

I know it seems very circuitous (and maybe unnecessary, depending on your
level of comfortability with writing DLLs in C++ and accessing them from
within a .NET app), but in my case it was very straightforward, because due
to other cirumstances of my app, I was already dynamically creating my
textboxes and holding an array of references to them - all I had to do was
add the event handler.

Hope this helps,

Luke Boyle
 
Dharth

We have implemented extensive coverage of trapping and dealing with keyboard
events in our McSoft Dynamic Framework product. You can download a trial
from www.mcsoft.com.au

It is also possible to license the source code to customise to your
requirements, or we may be able to help you achieve this.

Regards

Andrew
www.mcsoft.com.au
 
Back
Top