CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2005
    Posts
    95

    Reading keyboard within a sub

    Is there any way to read the keyboard WITHIN a sub that I create? I really only want to see if somone pushes the "a" or "A" key to abort a lengthy operation. I am trying to avoid DO EVENTS at all cost. I just rewrote a bunch of code to remove doevents after it almost gave me an ulcer---all works great now., but I lost the abort ability.

    Just wondering if reading the keyboard with a function or call is even possible.

    I suppose I could dice up the lenghty operation into multiple calls of my sub using statics & thus allow a click event to "jump in between calls" to effect an abort.

  2. #2
    Join Date
    Feb 2002
    Location
    Makati City, Philippines
    Posts
    1,054

    Re: Reading keyboard within a sub

    If you want to use the click event as interrupter - you can't do away with DoEvents. You may also try the Timer events if it will work on your needs.
    Marketing our skills - please participate in the survey and share your insights
    -

  3. #3
    Join Date
    Apr 2009
    Posts
    394

    Re: Reading keyboard within a sub

    GetAsyncKeyState API

    Good Luck

  4. #4
    Join Date
    Nov 2005
    Posts
    95

    Re: Reading keyboard within a sub

    Is is really impossible to read or look for a key within your own created routine? Seems like there should be a simple api call so you can: A=abort, D=decrease amount, I=increase amount, etc within your own loop.

    any ideas?

  5. #5
    Join Date
    Apr 2009
    Posts
    394

    Re: Reading keyboard within a sub

    From vb to vb, candies did you see my post #3???

    If you had, you would not have asked your retorical question in post #4...

  6. #6
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Reading keyboard within a sub

    Removing DoEvents may speed the app up on your system at the time, but it may lock up some other system that is doing different things (like playing music)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  7. #7
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Reading keyboard within a sub

    Ähmmm... did somebody mention the KeyPress() event?
    You set the focus to the element where you expect key input and the KeyPress() event will be easy to analyze what key has been pressed.

  8. #8
    Join Date
    Apr 2009
    Posts
    394

    Re: Reading keyboard within a sub

    Quote Originally Posted by WoF View Post
    Ähmmm... did somebody mention the KeyPress() event?
    You set the focus to the element where you expect key input and the KeyPress() event will be easy to analyze what key has been pressed.
    Ahhh....

    OP said in own sub/function which is looping and without the doevents....

  9. #9
    Join Date
    Jul 2006
    Location
    Germany
    Posts
    3,725

    Re: Reading keyboard within a sub

    Ahhh... right. Missed that.

Tags for this Thread

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured