• How to send Ctrl keystroke only? (A2K SP3)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » How to send Ctrl keystroke only? (A2K SP3)

    • This topic has 8 replies, 4 voices, and was last updated 22 years ago.
    Author
    Topic
    #385082

    If I just want to send a Ctrl keystroke when a bound textbox gets the focus, how could I do that? The line
    SendKeys “^”
    apparently doesn’t work as the keystroke isn’t recognised.

    I need the Ctrl keystroke to activate another non-Access program working in tandem with my Access application. At present, I need to press Ctrl key manually every time I need to activate the program.

    Viewing 0 reply threads
    Author
    Replies
    • #662985

      I’m afraid there isn’t any way to do it with SendKeys – the CTRL key is always used with another keystroke. In fact I am surprised that it is recognized in a manual mode when Access is the active application – Windows in general does’t recognize CTRL by itself. Is this some sort of DOS App?

      • #663195

        No, it isn’t, Wendell. It is a Windows program now in its WinXP version. It is a CJK-input program in which pressing a Ctrl key would bring up the character-input screen and user can key in CJK characters for input in a bound control, say, and pressing Ctrl again would toggle it off. Is there any other method of sending a key besides Sendkeys?

        • #663223

          Ahhh! I understand what you are trying to do now – unfortunately I don’t have any experience with entry of UniCode characters into a text box. It would seem however that you should be able to trigger the input program as soon as a text box (or other text control) get focus. Hopefully someone with more experience in this area can make a suggestion.

          • #663367

            I surfed the Net and came out with these codes to simulate pressing and releasing of a Ctrl key :

            Private Const VK_CONTROL = &H11
            Private Const KEYEVENTF_KEYUP = &H2
            Private Const KEYEVENTF_EXTENDEDKEY = &H1

            Private Declare Sub keybd_event Lib “user32” _
            (ByVal bVk As Byte, _
            ByVal bScan As Byte, _
            ByVal dwFlags As Long, _
            ByVal dwExtraInfo As Long)

            ‘ Simulate pressing CTRL key
            Function ToggleEntry()
            ‘ Simulate Key Press
            keybd_event VK_CONTROL, 0, KEYEVENTF_EXTENDEDKEY Or 0, 0
            ‘Simulate Key Release
            keybd_event VK_CONTROL, 0, KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0
            End Function

            Pressing the CTRL key once will activate the CJK-Input screen of my application which is already loaded into the computer memory, and pressing CTRL key a second time will de-activate it and Access will accept English input normally.

            The codes worked perfectly in debug mode when I stepped through the ToggleEntry() codes line by line. The CJK-Input screen of my application was activated and de-activated as expected. However, when I executed the codes normally, it didn’t work. Why?

            • #663395

              Does it help if you insert DoEvents between the two instructions in ToggleEntry, or just before the End Sub, or both?

            • #663416

              No, Hans, it doesn’t work when I inserted DoEvents in between the two keyboard events and/or just before End Sub. Sigh.

              Regards,
              Lesoch.

            • #663530

              What happens if you try a 1 second wait loop after the first of the 2 commands?
              Pat

            • #663618

              Hans, I inserted the DoEvents just before End Sub in my 386 WinMe machine, the codes worked magically. On my Pentium 4 WinXP machine, the codes didn’t work.

              Based on Pat’s suggestion, I added the loop below:

              Dim i As Integer
              For i = 1 To 1000 ‘ Set up counting loop (the loop can be reduced further)
              DoEvents
              Next i

              The codes also work in my WinXP machine now.

              My sincere thanks to Wendell, Hans and Pat for your help. But can someone explain to me why it appeared that timing was important in this case?

    Viewing 0 reply threads
    Reply To: How to send Ctrl keystroke only? (A2K SP3)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: