Results 1 to 18 of 18

Thread: wats wrong !!!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2012
    Posts
    339

    wats wrong !!!

    how to detect key up and down events outside form ...

    i use this code but it works till c as i use this code for d and other keys it does not work

    If GetAsyncKeyState(vbKeyb) <> 0 Then (key down)
    Label1.Caption = "b is pressed"
    Else
    If GetAsyncKeyState(vbKeyB) = 1 Then (key up)
    label1.caption= "b is released"
    end if
    end if



    wat to do
    Last edited by useruseronline; Jul 13th, 2012 at 03:36 PM.

  2. #2
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: wats wrong !!!

    You are saying you use that exact code for a, b, and c, even though you are only testing for b and it works for those three letters but stops working at d and beyond?


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  3. #3
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: wats wrong !!!

    i would try something different then If Then Else

    Declarations

    Code:
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    Private Const vbKeyB_Released As Integer = 0
    Private Const vbKeyB_Up As Integer = 1
    Private Const vbKeyB_Down As Integer = -32767
    Timer
    Code:
    Select Case GetAsyncKeyState(vbKeyB)
       Case vbKeyB_Down '(key down)
          Label1.Caption = "b is pressed"
    
       Case vbKeyB_Up, vbKeyB_Released '(key up) (key released)
          Label1.Caption = "b is released"
    End Select
    and YES YOU CAN use only 0,1,-32767 in the select case which would be alot better

    vb Code:
    1. Select Case GetAsyncKeyState(vbKeyB)
    2.    Case Is = -32767 '(key down)
    3.       Label1.Caption = "b is pressed"
    4.  
    5.    Case Is = 0, Is = 1 '(key up) (key released)
    6.       Label1.Caption = "b is released"
    7. End Select
    Last edited by Max187Boucher; Jul 13th, 2012 at 08:11 PM.

  4. #4
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: wats wrong !!!

    If you look at the post I gave you in your other thread I showed you there how to detect key up so you could get that count problem you had straightened out. You never replied back so I assumed you never went back there.


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  5. #5
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: wats wrong !!!

    try this
    Code:
    Option Explicit
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    
    Function KeyB() As Boolean
    KeyB = CBool(GetAsyncKeyState(vbKeyB))
    End Function
    
    Private Sub Form_Load()
    Timer1.Interval = 1
    End Sub
    
    Private Sub Timer1_Timer()
    If KeyB = True Then
        Label1.Caption = "B Down"
    Else
        Label1.Caption = "B Up"
    End If
    End Sub
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    May 2012
    Posts
    339

    Re: wats wrong !!!

    thanks guys its works but how to implement it for other keys ???

  7. #7
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: wats wrong !!!

    The same way as shown and it should work just fine.

    Your initial code would not have worked even though you said it did.
    Code:
    If GetAsyncKeyState(vbKeyb) <> 0 Then (key down)
    Label1.Caption = "b is pressed"
    Else
    If GetAsyncKeyState(vbKeyB) = 1 Then (key up)
    label1.caption= "b is released"
    end if
    end if
    The part in Red would only execute if the result were 0 but then it tests to see if the result is 1 which it would never be at that point so it would always fail

  8. #8
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    May 2012
    Posts
    339

    Re: wats wrong !!!

    Quote Originally Posted by seenu_1st View Post
    try this
    Code:
    Option Explicit
    Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    
    Function KeyB() As Boolean
    KeyB = CBool(GetAsyncKeyState(vbKeyB))
    End Function
    
    Private Sub Form_Load()
    Timer1.Interval = 1
    End Sub
    
    Private Sub Timer1_Timer()
    If KeyB = True Then
        Label1.Caption = "B Down"
    Else
        Label1.Caption = "B Up"
    End If
    End Sub
    this code works fine with b but how to implment it for other keys ?? like a down and up c down and up

  10. #10
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: wats wrong !!!

    may i knw what purpose u r doing this?
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    May 2012
    Posts
    339

    Re: wats wrong !!!

    m making a piano type project , when a pressed it will play sound when released it will play echo ...

  12. #12
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: wats wrong !!!

    but why the piano detect keyboard when application not in focus?
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  13. #13

    Thread Starter
    Hyperactive Member
    Join Date
    May 2012
    Posts
    339

    Re: wats wrong !!!

    its like gadget tool in windows 7 if i am on other application if detects keys and plays piano as i type in other application

  14. #14
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: wats wrong !!!

    That would be a pretty lame thing to have on a pc, based on previous posts it sounds like you are trying to create an invisible keylogger.

  15. #15

    Thread Starter
    Hyperactive Member
    Join Date
    May 2012
    Posts
    339

    Re: wats wrong !!!

    if i had to make keylogger i woudnt have asked here its availible at youtube ...

  16. #16
    Just a Member! seenu_1st's Avatar
    Join Date
    Aug 2007
    Location
    India
    Posts
    2,170

    Re: wats wrong !!!

    Quote Originally Posted by useruseronline View Post
    if i had to make keylogger i woudnt have asked here its availible at youtube ...
    as per the forum rule, we shuldnt help which is related to keylogger, sorry.
    Seenu

    If this post is useful, pls don't forget to Rate this post.
    Pls mark thread as resolved once ur problem solved.
    ADO Tutorial Variable types SP6 for VB6, MsFlexGrid fast fill, Sorting Algorithms


  17. #17

    Thread Starter
    Hyperactive Member
    Join Date
    May 2012
    Posts
    339

    Re: wats wrong !!!

    ok thanks as u well comforatble

  18. #18
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: wats wrong !!!

    Quote Originally Posted by useruseronline View Post
    if i had to make keylogger i woudnt have asked here its availible at youtube ...
    What you are asking for is the basis of a key logger e.g. Capture keypresses outside your app. A logger would save them to a text file or something but regaurdless of what you say you want to do if we showed you how then there would be a sample for others to do key loggers and quite frankly making keys paly a piano sound when I am typing on a forum would be a horrible thing to have installed on a system it would never play a tune just wierd random notes.

    Combine what you are asking here with previous posts where you wanted to hide your program from task manager, make it to where the process could not be killed by the user and so on and it sounds like you are trying to write something that would be a violation of the rules and possibly the law.

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