Sending keystrokes via code in Access 2000?

/usr/usr Member Posts: 1,768
Anyone know how to do this?

I've got an option group with two buttons. When one of the buttons gets the focus via a shortcut key such as 'F', I want to simulate the pressing of the spacebar in order to depress the button.

I'm not having much luck with the builtin SendKeys method.

Anyone have an idea?

Comments

  • WebmasterWebmaster Admin Posts: 10,292 Admin
    Last time I done something like that was with access 2.0 ten years ago, so I may be way off here, but isn't there a way to set the button to depress the button that you can activate when pressing the F key? i.o.w. a property for the button that you can set in the same section as the Setfocus.
  • /usr/usr Member Posts: 1,768
    There's an OptionValue for the buttons, but I haven't had much luck with it in this case. Here's a bit more information on my situation.

    I have a Pass and a Fail button.

    When you press the 'F' shortcut key, the Fail button will go down, but won't stay down if you tab off of it. If you press 'F' to jump to the Fail button, then press the space key, it will stay depressed when you tab off. Likewise for a click of the mouse.

    For some reason, the shortcut key isn't actually "pressing" the button and it's defaulting back to the pass button when you tab off the control.

    Hence the reason I wanted to send a 'Space' keystroke when they navigate to that button.
  • WebmasterWebmaster Admin Posts: 10,292 Admin
    I'm trying to dig here but I cannot think of what it was exactly but this (automating user input, a key stroke, to get certain results) just sounds so familiar. I understand why you want it, but it's taking the wrong approach as you should code the results directly instead of coding an action to get the results.
    When you press the 'F' shortcut key, the Fail button will go down, but won't stay down if you tab off of it. If you press 'F' to jump to the Fail button, then press the space key, it will stay depressed when you tab off.
    Probably 'normal default behavior' but it sounds weird to me. Why does it stay depressed after hitting space...? Not very useful for solving your problem probably, just curious, are these On/Off buttons? What does the application/form do?
  • /usr/usr Member Posts: 1,768
    It's a data collection application used by associates on a production line. A unit passes or fails and they click the corresponding button.

    They are toggle buttons, so only one can be depressed at once.

    And yes, it is weird. I've even tried calling the MouseDown method when the button gets the focus, to simulate a mouse click, but it doesn't work.

    I have code executing on the KeyDown method, which executes when the button gets the focus as a result of the 'P' or 'F' shortcut keys.

    Basically, it's just a visual thing, because the underlying code is working properly. If the user Fails a unit, but moves to the next field and sees the Pass button depressed, they're going to question it, even though the underlying database is still reading that the unit Failed.

    It's tough to explain...I apologize for the confusion.
  • /usr/usr Member Posts: 1,768
    I just found out something strange.

    If I press the 'F' key to move to the Fail button, then press the 'F' key again, it works.

    It's like the first press of the 'F' key simply moves the focus to the button, rather than pressing it.

    The 'P' key doesn't do this, since the Pass button gets the focus by default when they tab into the Option group.

    Any suggestions? icon_wink.gif
  • /usr/usr Member Posts: 1,768
    Fixed it with SendKeys "F", when the button gets the focus.

    icon_lol.gif
  • 2lazybutsmart2lazybutsmart Member Posts: 1,119
    aha. SendKeys, that's the function. I just didn't understand why I dind't work for you at first.

    If you were in VB or something, you could activate the KeyPreview of the whole form and users would just have to press those keys no matter where the current focus is. What's killing you is the focus. A control's mouse and keybord methods execute only when there's a focus.

    You do access database applications? I thought you were into security and stuff icon_lol.gif

    2lbs.
    Exquisite as a lily, illustrious as a full moon,
    Magnanimous as the ocean, persistent as time.
  • /usr/usr Member Posts: 1,768
    I like security and stuff, but I don't deal with it at my current job.
Sign In or Register to comment.