Results 1 to 7 of 7

Thread: [RESOLVED] GetAsyncKeyState

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Location
    Washington DC
    Posts
    314

    Resolved [RESOLVED] GetAsyncKeyState

    I've been playing with this, and have writting a nice program for my own use.

    This program, however, is designed to stay open while I go do other stuff.

    My problem: I can be in an entirely different window, yet if I hit one of the keys my program is reading, it tries to process it, causing great confusion to me.

    So I am looking for

    GetAsyncKeyStateButOnlyIfMyWindowIsActive

    LOL

    or, failing that, a test to see if my window is active. I could put that in the timer loop to ignore everything unless I am active.

    Or maybe there is a better way? For example, a SUB to get control when my program becomes inactive (which could turn off the timer) and another one when it becomes active again (to turn timer on)

  2. #2
    Hyperactive Member
    Join Date
    Aug 2006
    Posts
    367

    Re: GetAsyncKeyState

    Any reason why KeyDown/KeyUp events aren't sufficient? Thats the path of least resistance.. Aside from that, just nest your GetAsyncKeystate inside a GetWindowPos type IF statement..

  3. #3
    Lively Member ixtrip's Avatar
    Join Date
    Aug 2005
    Posts
    64

    Re: GetAsyncKeyState

    You could try to use GetForegroundWindow

    vb Code:
    1. Public Declare Function GetForegroundWindow Lib "user32" () As Long
    2.  
    3. if GetForegroundWindow = me.hwnd then
    4. 'top window
    5. else
    6. 'not top
    7. end if

    And throw it into a timer? Doesn't use up too much memory :-P I'm trying to think of somethin else but i would try keydown, keyup first...if i think of anything i'll throw it in here..

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Location
    Washington DC
    Posts
    314

    Re: GetAsyncKeyState

    Quote Originally Posted by triggernum5
    Any reason why KeyDown/KeyUp events aren't sufficient
    n00b = Mac

    Actually, first I saw some stuff about GetAsyncKeyState and then I wrote a program around it just to see how it works and forgot that I didn't have to do that.

    But after your suggestion, I ripped out all the TIMER/GetAsyncKeyState stuff and replaced it with KeyDown/KeyUp stuff. MUCH SIMPLER!!!

    Thanks!!

    Mac

  5. #5
    Lively Member ixtrip's Avatar
    Join Date
    Aug 2005
    Posts
    64

    Re: GetAsyncKeyState

    You learn somethin new everyday ;-)

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2001
    Location
    Washington DC
    Posts
    314

    Re: GetAsyncKeyState

    Quote Originally Posted by ixtrip
    You learn somethin new everyday ;-)
    LOL - Yep.

    What didn't occur to me was that the GetAsyncKey stuff was really intended to get keypresses when you program was NOT in control. For example, a key logger. Or a program to wait for hot-keys and then initiate something.

    It had no utility at all for a program that was in control. That program could simply read key events the normal way.

    Oh, well. Live and learn. Actually, live and learn what you once knew already.

    Mac

  7. #7
    Hyperactive Member
    Join Date
    Aug 2006
    Posts
    367

    Re: GetAsyncKeyState

    Actually, remember for the future that hotkeys have their own APIs.. RegisterHotkey and UnregisterHotkey IIRC.. Although you could build your own system with GetAsyncKeystate.. GetAsyncKeyState can go pretty hardcore if you dive into complex params..

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