Results 1 to 9 of 9
  1. #1
    2 Star Lounger
    Join Date
    Feb 2002
    Posts
    155
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to send Ctrl keystroke only? (A2K SP3)

    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.

  2. #2
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: How to send Ctrl keystroke only? (A2K SP3)

    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?
    Wendell

  3. #3
    2 Star Lounger
    Join Date
    Feb 2002
    Posts
    155
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to send Ctrl keystroke only? (A2K SP3)

    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?

  4. #4
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: How to send Ctrl keystroke only? (A2K SP3)

    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.
    Wendell

  5. #5
    2 Star Lounger
    Join Date
    Feb 2002
    Posts
    155
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to send Ctrl keystroke only? (A2K SP3)

    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?

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: How to send Ctrl keystroke only? (A2K SP3)

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

  7. #7
    2 Star Lounger
    Join Date
    Feb 2002
    Posts
    155
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to send Ctrl keystroke only? (A2K SP3)

    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.

  8. #8
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Re: How to send Ctrl keystroke only? (A2K SP3)

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

  9. #9
    2 Star Lounger
    Join Date
    Feb 2002
    Posts
    155
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to send Ctrl keystroke only? (A2K SP3)

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •