[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1256
  • Last Modified:

SendKeys

Hello,

I am writing a program on a handheld in Visual Basic .NET.  Unfortunatly, this uses the .NET Compact Framework instead of just the normal .NET Framework package, but it is still VB.NET :)

I have a bunch of button on the screen, touch screen buttons that the users prefer to use over the numeric keys themselves on the handheld device.  some of the time these buttons represent words or letters and i have programmed for that.  However, most of the time the buttons just represent numbers.  I do not want to write code for the buttons to tell them where to write a "1" to, instead i just want to make the button act as though they hit the numeric key.  I thought this might have been with the SendKey function but I am not having any luck.  It may be because I do it wrong or it may be because the .NET Compact Framework will not support it.  A simple example of how to do something like this would be much apperciated!  

Thanks

-Navicerts
0
Navicerts
Asked:
Navicerts
  • 2
  • 2
1 Solution
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
When you "click" the button it has the focus...and thus it will receive the keystroke you generate.  Probably not what you wanted...

You need a way to track the control that LAST had the focus before the button was clicked.  Then you can focus that control again before sending your keystroke.

This can be as simple as declaring a variable to reference the last focused control.  Add handlers for the GotFocus() event of all controls that should receive keystrokes.  In the GotFocus() event, simple set your global variable to whatever control got the focus (the "sender" parameter).

    Private lastControl As Control

    ...  

    If Not IsNothing(lastControl) Then
        lastControl.Focus()
        ' send keystrokes
    End If
0
 
NavicertsAuthor Commented:
I thought there might have been something easier, maybe a bit more clean that was used for touch screen buttons.  Seems kinda messy to me, to have to add in code to all the controls.  I guess i was looking for a way to hit the button without loosing focus on the current control, basically never give the button the focus.  I probally hoped for too much :)
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
"to have to add in code to all the controls."

You don't need seperate code for each control.

Iterate over the Controls collection in the Form_Load() event (or whatever the CF equivalent is) and use the AddHandler() function to wire up all the desired controls.  You can use the TypeOf function to determine the type of each control so you can only wire up TextBoxes for instance.

I don't have CF experience but I can show you WinForms code...
0
 
NavicertsAuthor Commented:
I'll run with what you gave me so far and see how far i make it :)  I post again if i cant figure it out, thank you sir!

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now