Macro recording?

Just starting out? Need help? Post your questions and find answers here.
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Macro recording?

Post 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.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> see if it gets you started

Thanks Sparkie, it is indeed a great starting point! :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
HeX0R
Addict
Addict
Posts: 1189
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Post by HeX0R »

hmm....
Logging keystrokes, getting XP-Keys ...
What kind of application this could be ? :roll:
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post 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?)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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. :)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
thefool
Always Here
Always Here
Posts: 5875
Joined: Sat Aug 30, 2003 5:58 pm
Location: Denmark

Post 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
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post 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.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post 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:
--Kale

Image
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

@Kale: Don't make me bitch-slap you! :twisted:
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Kale
PureBasic Expert
PureBasic Expert
Posts: 3000
Joined: Fri Apr 25, 2003 6:03 pm
Location: Lincoln, UK
Contact:

Post by Kale »

:twisted:
--Kale

Image
Dare2
Moderator
Moderator
Posts: 3321
Joined: Sat Dec 27, 2003 3:55 am
Location: Great Southern Land

Post by Dare2 »

:D
@}--`--,-- A rose by any other name ..
johnfermor
User
User
Posts: 29
Joined: Wed Dec 31, 2003 3:17 pm

Not one to take sides ...

Post by johnfermor »

But I'm with PB

He's helped me out a couple of times!

Cheers
User avatar
HeX0R
Addict
Addict
Posts: 1189
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Post 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
Post Reply