Page 1 of 2

Macro recording?

Posted: Sat Dec 04, 2004 6:53 am
by PB
I'm just dabbling in this for the first time and it's actually quite hard to do.
I want to record every keystroke and mouse click. It's easy enough to do
except when it comes to multiple keystrokes -- for example, if the user hit
CTRL+C (to copy). I don't know how to tell that CTRL+C were hit together,
as opposed to CTRL down/up first and then C down/up. Any tips on this?
I actually should know this but for some reason my brain's not working.

Posted: Mon Dec 06, 2004 3:28 am
by Sparkie
I found this oldie in one of my folders. For some reason I never finished optimizing the code, but see if it gets you started. :wink:

Code: Select all

Enumeration
  #Window_0
EndEnumeration

Enumeration
  #String_0
  #Text_0
  #Text_1
  #Text_2
  #Text_3
  #Text_4
EndEnumeration

Global OldCallback, key$, vk$
key$ = Space(255)

Procedure String0_CallBack(hwnd, msg, wparam, lparam) 
  Select hwnd
    Case GadgetID(#String_0)
      gadID$ = "#String_0"
      If wparam = #VK_TAB ; catch the tab key
        GetKeyNameText_(lparam,key$,255)
        SetGadgetText(#Text_2,  key$)
        SetGadgetText(#Text_3, "")
      EndIf
  EndSelect
  Select msg
    Case #WM_KEYDOWN ; get the key pressed
      GetKeyNameText_(lparam,key$,255)
      SetGadgetText(#Text_2, key$)
      SetGadgetText(#Text_3, "")
    Case #WM_CHAR ; display valid charater
      lShift = GetAsyncKeyState_(#VK_LSHIFT)
      rShift = GetAsyncKeyState_(#VK_RSHIFT)
      lCtrl = GetAsyncKeyState_(#VK_LCONTROL)
      rCtrl = GetAsyncKeyState_(#VK_RCONTROL)
      Debug rCtrl
      If lShift < 0
        vk$ = "Left Shift + "
      ElseIf rShift < 0
        vk$ = "Right Shift + "
      ElseIf lCtrl < 0
        vk$ = "Left Control + "
      ElseIf rCtrl < 0
        vk$ = "Right Control + "
      Else
        vk$ = ""
      EndIf
      SetGadgetText(#Text_2, vk$ + key$)
      If wparam <> 38 And wparam > 26
        SetGadgetText(#Text_3, Chr(wparam))
      ElseIf wparam = 38
        SetGadgetText(#Text_3, "&" + Chr(wparam))
      EndIf
    Case #WM_SYSCHAR
      lAlt = GetAsyncKeyState_(#VK_LMENU)
      rAlt = GetAsyncKeyState_(#VK_RMENU)
      If lAlt <> 0
        vk$ = "Left Alt + "
      ElseIf rAlt <> 0
        vk$ = "Right Alt + "
      Else
        vk$ = ""
      EndIf
      SetGadgetText(#Text_2, vk$ + key$)
    Case #WM_SYSKEYDOWN ; catch the Alt keys
      GetKeyNameText_(lparam,key$,255)
      SetGadgetText(#Text_2, key$)
      lrAlt$ = key$
  EndSelect
  ProcedureReturn CallWindowProc_(OldCallback, hwnd, msg, wparam, lparam) 
EndProcedure 

If OpenWindow(#Window_0, 0, 0, 300, 150,  #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_TitleBar , "Key Pressed")
  If CreateGadgetList(WindowID())
    TextGadget(#Text_0, 20, 60, 100, 20, "Key Pressed", #PB_Text_Right)
    TextGadget(#Text_1, 20, 90, 100, 20, "Character displayed", #PB_Text_Right)
    TextGadget(#Text_2, 130, 60, 100, 25, "")
    TextGadget(#Text_3, 130, 90, 50, 25, "")
    TextGadget(#Text_4, 130, 120, 50, 25, "")
    StringGadget(#String_0, 20, 5, 260, 20, "")
    ActivateGadget(#String_0)
    OldCallback = SetWindowLong_(GadgetID(#String_0), #GWL_WNDPROC, @String0_CallBack())
    SetWindowLong_(GadgetID(#String_0), #GWL_WNDPROC, @String0_CallBack()) 
  EndIf
EndIf
Quit = #False
Repeat
  event = WaitWindowEvent()
  Select event
    Case #PB_EventCloseWindow
      Quit = #True
  EndSelect
Until Quit
End

Posted: Mon Dec 06, 2004 6:07 am
by PB
> see if it gets you started

Thanks Sparkie, it is indeed a great starting point! :)

Posted: Mon Dec 06, 2004 12:36 pm
by HeX0R
hmm....
Logging keystrokes, getting XP-Keys ...
What kind of application this could be ? :roll:

Posted: Mon Dec 06, 2004 6:16 pm
by blueznl
pb has been around for a while... so we may think of him as reliable... unlike someone called omidxp

(hey, a virus surfaced that does grab your webcam input... jeez.... think he finally became a real programmer, that omidxp?)

Posted: Mon Dec 06, 2004 7:59 pm
by PB
> Logging keystrokes, getting XP-Keys ...
> What kind of application this could be ?

For starters, I never said these two things were for the one single app...

As blueznl said, I've been around here for a long time (look at your post
count compared to mine, HeX0R) and people know my nature. In fact,
I've already posted a powerful keystroke tip before (see my post here:
viewtopic.php?t=3766 ) so it's not like
I don't know how to "do things" to people's systems (if I wanted to). :)
I have a friend who uses an app I wrote for him that used my keystroke tip,
but now he's asked if I could make it record macros for him so save him from
having to compose them manually -- so that's all I'm trying to do now.

As for getting the XP CD key -- so what? Again, people who know me here
know that I have zero knowledge of networking, so it's not like I'm going to
secretly grab the key and upload it somewhere. It's for an info-type app
that I'm writing, that shows people stats about their system. If you'd look
at my early posts you'd see that I've asked how to get the HD size, RAM
size, etc -- but as soon as I ask about the XP CD key I get hassled? :)
For the record, I already knew how to get the 95, 98, and ME keys, but
the 2000 and XP keys are encrypted, so that's why I wanted to know how
to decrypt them. You should have been more worried if I asked how to
get ANY Windows key, as that would indicate a more suspicious app, no?

At the end of the day, I know I have a good reputation here as someone
totally trustworthy and helpful to this community. I know lots of people
would come to my defense, as blueznl already has. But I do see how my
questions could alarm you, so I'm not too surprised. This reply is just to
calm your suspicions. :)

Posted: Mon Dec 06, 2004 8:03 pm
by thefool
Actually at purearea.net, you can get a nice mouse-recorder.
http://www.purearea.net/pb/showcase/sho ... =20&sort=2

Coded by Mischa Brandt, maybe he can post the source or help you.
I know I have a good reputation here
hehe

Posted: Mon Dec 06, 2004 8:22 pm
by Sparkie
PB is quite often found lending a helpful hand around here, and IMHO, that's a trait found mainly in good hearted souls. :)

After past experiences, I tend to be very careful before posting some code if I think it's going to be applied and used for evil purposes. In this case with PB, I never thought twice about posting it. 8)

Posted: Mon Dec 06, 2004 8:50 pm
by PB
> I tend to be very careful before posting some code if I think it's going to be
> applied and used for evil purposes. In this case with PB, I never thought
> twice about posting it.

Thanks, Sparkie. :) As I said the top, I already know how to log keystrokes
(see: viewtopic.php?p=12762 ) -- I just didn't
know the best way to log multiple keystrokes, which a macro recorder would
obviously need to do.

Posted: Mon Dec 06, 2004 9:04 pm
by Kale
At the end of the day, I know I have a good reputation here as someone
totally trustworthy and helpful to this community. I know lots of people
would come to my defense, as blueznl already has.
Yep HeX, PB can be trusted!* :)

*most of the time! he he... :twisted:

Posted: Mon Dec 06, 2004 9:48 pm
by PB
@Kale: Don't make me bitch-slap you! :twisted:

Posted: Mon Dec 06, 2004 11:28 pm
by Kale
:twisted:

Posted: Wed Dec 08, 2004 12:05 am
by Dare2
:D

Not one to take sides ...

Posted: Wed Dec 08, 2004 12:47 am
by johnfermor
But I'm with PB

He's helped me out a couple of times!

Cheers

Posted: Sat Dec 11, 2004 9:42 am
by HeX0R
Wow...
My answer should have been nothing but a joke.

It seems to be a very sensitive theme here ?
Strange...
The first trojan horse was meant to be a remote-desktop-control, so i see no sense to give those horses such a bad stamp.

But o.k.
sorry pb