Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2003
    Posts
    172

    Unanswered: trapping keystrokes

    Here's the scenario:

    I want to prevent users from clicking ahead on some forms until some processes are finished. I know the keyboard can store keystrokes so I want to basically intercept and do something with these keys or cancel the keystroke event. I want the same for the mouse events.

    The problem is actually on a VB form but Access is part of the project so it is affecting the whole project.

    Example,

    Jim clicks on the Start Process button with the mouse or enter key or hotkey. Jim wants to click ahead to restart the process when the first one completes - I want to trap that click and discard it until I am ready to let Jim press or click the button once again.

    I find that even if I disable the button temporarily, as soon as I re-enable it the button is clicked from the stored mouse or keystroke.

    I'm sure this is an easy one - I just haven't done keypress and mouse events for a while and don't want to spend 3 hours figuring this out.

    TIA

  2. #2
    Join Date
    Feb 2004
    Location
    New Zealand
    Posts
    1,418
    Provided Answers: 7
    I would

    use the object.Enable = Ture / False

    you can enable a button but first SetFocus to something else
    eg

    Code:
    Private Sub Command13_Click()
    Do something
    me.text1.SetFocus  '  < must do this
    Command13.Enabled = False
    do next thing
    Command13.Enabled = True
    End Sub
    hope this help

    See clear as mud


    StePhan McKillen
    the aim is store once, not store multiple times
    Remember... Optimize 'til you die!
    Progaming environment:
    Access based on my own environment: DAO3.6/A97/A2000/A2003/A2007/A2010
    VB based on my own environment: vb6 sp5
    ASP based on my own environment: 5.6
    VB-NET based on my own environment started 2007
    SQL-2005 based on my own environment started 2008
    MYLE
    YOUR PASSWORD IS JUST LIKE YOUR TOOTHBRUSH DON'T SHARE IT.

  3. #3
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1
    If you want to enable the keyboard trapping then set KeyPreview to TRUE on your main form or other fomrs you want

  4. #4
    Join Date
    Dec 2003
    Posts
    172
    Tried enable disable (but I didn't change the focus - maybe that might help prevent extra keystrokes falling on the button once re-enabled.) As far as the keypress usage - could you give me a little more info on this. Thanks.

    Joe G

  5. #5
    Join Date
    Oct 2003
    Location
    Ger
    Posts
    1,969
    Provided Answers: 1

    Lightbulb

    In your Open Form event put Me.KeyPreview = True

    PHP Code:
    Private Sub Form_KeyDown(KeyCode As IntegerShift As Integer)
        If 
    KeyCode vbKeyF9 Then
          MsgBox 
    "F9 was pressed"vbInformation
        End 
    If
    End Sub 
    In this way you could trap all key strokes on that form, but that is thing and SetFocus is another thing. I don't understand your problem with the SetFocus.

Posting Permissions

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