Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Onscreen keyboard focus issues

Posted on 2004-10-05
8
Medium Priority
?
458 Views
Last Modified: 2007-12-19
Hi

I have created an onscreen keyboard and

topmost = true
and i use the sendkeys.send(data) to send

but my program keeps setting focus back on the keyboard when pressed

how do I stop that from happening

Thanks
Adam
0
Comment
Question by:adam_pedley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 18

Accepted Solution

by:
armoghan earned 1500 total points
ID: 12225212
get the process ID of the other window and set it active
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12225225
following links may help in getting the handle of the window and making focus on it
http://www.codeproject.com/csharp/windowhider.asp
http://www.error-bank.com/microsoft.public.dotnet.framework/71290_Thread.aspx
0
 
LVL 18

Expert Comment

by:armoghan
ID: 12225236
0
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!

 
LVL 27

Expert Comment

by:planocz
ID: 12226716
Try this sample to catch key strokes before it gets to your keypress events....


  Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
        Const WM_KEYDOWN As Integer = &H100
        Const WM_SYSKEYDOWN As Integer = &H104
        Dim e As System.EventArgs

        If ((msg.Msg = WM_KEYDOWN) Or (msg.Msg = WM_SYSKEYDOWN)) Then
            Select Case (keyData)
                'The Number Key Pads, 10 key and regular 0-9 keys
            Case Keys.A
                    'DO SomeThing
                Case Keys.NumPad1, Keys.D1
                                   'DO SomeThing
                Case Keys.NumPad2, Keys.D2
                                   'DO SomeThing
                Case Keys.B
                                  'DO SomeThing
            End Select
        End If
        Return MyBase.ProcessCmdKey(msg, keyData)
    End Function
0
 
LVL 4

Author Comment

by:adam_pedley
ID: 12233183
Public Class Keypad
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Private Declare Function GetForegroundWindow Lib "user32" () As Long
    Private Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
    Private first_time As Boolean = False
    Private This_App As Long
    Private last_app As Long

    'Enables light when caps lock button is pressed
    Private Sub Caps_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Caps.Click
        If lblCaps.BackColor.Equals(Color.Silver) Then
            lblCaps.BackColor = Color.LightGreen
        Else
            lblCaps.BackColor = Color.Silver
        End If
    End Sub

    Private Sub Keypad_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Start()
    End Sub

    'Detects a button is clicked and gives the value of the button pressed to the key press function (Only keys A-Z 0-9)
    Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles A.Click, B.Click, C.Click, D.Click, E.Click, F.Click, G.Click, H.Click, I.Click, J.Click, K.Click, L.Click, M.Click, N.Click, O.Click, P.Click, Q.Click, R.Click, S.Click, T.Click, U.Click, V.Click, W.Click, X.Click, Y.Click, Z.Click, _0.Click, _1.Click, _2.Click, _3.Click, _4.Click, _5.Click, _6.Click, _7.Click, _8.Click, _9.Click, _Dot.Click
        Key_Press(sender.text)
    End Sub

    'Displays the key pressed on the screen
    Private Sub Key_Press(ByVal value As String)
        'Detects if caps lock is on, if so it converts the character to uppercase or lowercase
        If lblCaps.BackColor.Equals(Color.LightGreen) Then
            value = value.ToUpper()
        Else
            value = value.ToLower()
        End If
        'Displays the keypressed on the screen
        'txtText.Text = txtText.Text & value
        set_focus()
        SendKeys.Send(value)
    End Sub


    'Removes a character from the screen
    Private Sub BackSpace__Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BackSpace_.Click
        set_focus()
        SendKeys.Send(Chr(8))
    End Sub

    'Adds a space to the screen
    Private Sub Space_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Space.Click
        set_focus()
        SendKeys.Send(" ")
    End Sub

    'Creates a new line to the screen
    Private Sub Enter__Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Enter_.Click
        set_focus()
        SendKeys.Send(Chr(13))
    End Sub

    Public Sub set_focus()
        SetForegroundWindow(last_app)
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If first_time = False Then
            first_time = True
            This_App = GetForegroundWindow
        End If
        If This_App <> GetForegroundWindow Then
            last_app = GetForegroundWindow
        End If
    End Sub
End Class

Ok that is my code, I managed to work out the getforegroundwindow function, but my problem now, is that it requires a timer to keep detecting the current window and will switch focus back to the other one if the keypad is pressed. I have seen an example in Delphi (not .NET) that you can open a window with no_activate. This would be my preferred preference. I wouldnt have to have the timer and stupid holes in my code.

Does anyone know how to do this?
0
 
LVL 4

Author Comment

by:adam_pedley
ID: 12233687
I have found out some additional information on the no_activate which i will share here, hopefully someone will be able to figure the rest out

This URL has a few people explaining it slightly but no examples or anything
http://www.eggheadcafe.com/ng/microsoft.public.vb.winapi.graphics/post558542.asp

This URL shows a code example of calling a form and setting the no activate function
http://vbnet.mvps.org/index.html?code/forms/setlayeredwindowattributes.htm

Here is the MSDN link for it
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcemfc/htm/cwnd_192.asp

hope this helps in someway
0
 
LVL 4

Author Comment

by:adam_pedley
ID: 12234164
this question is obviously stumping people, i have never had a question open so long

I am upping the points to 1000 (i will open another 500 point question for the user to get the rest of the points once this is answered)
0
 
LVL 4

Author Comment

by:adam_pedley
ID: 12244916
Ok im going to repost the question with the new twist to it
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question