Variables when calling SRT from OnEvent

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Grovkillen
Automation Wizard
Posts: 1024
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Variables when calling SRT from OnEvent

Post by Grovkillen » Tue Aug 22, 2023 5:19 pm

Please test this and see if the same thing happens to you. The script will not go back to the loop once you have called the TEST_SRT using the "h" key which is calling the sub routine together with a variable.

Code: Select all

//this one will not jump back to the loop after SRT is done, it will jump to the beginning of the script...
OnEvent>KEY_DOWN,VK72,0,TEST_SRT,{"h"}
//this one work (i key)
OnEvent>KEY_DOWN,VK73,0,TEST_SRT
//ESC=close app
OnEvent>KEY_DOWN,VK27,0,CLOSE_APP

Label>RESTART_LOOP
Wait>0.02
Goto>RESTART_LOOP

SRT>CLOSE_APP
  Exit>
END>CLOSE_APP

SRT>TEST_SRT
**BREAKPOINT**
//F8 to step through
END>TEST_SRT
Let>ME=%Script%

Running: 15.0.24
version history

User avatar
Grovkillen
Automation Wizard
Posts: 1024
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Variables when calling SRT from OnEvent

Post by Grovkillen » Tue Aug 22, 2023 5:21 pm

I found this bug 2021 :) viewtopic.php?f=2&t=11062
Let>ME=%Script%

Running: 15.0.24
version history

User avatar
JRL
Automation Wizard
Posts: 3501
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Variables when calling SRT from OnEvent

Post by JRL » Wed Aug 23, 2023 9:16 pm

Grovkillen,
I have also experienced this phenomenon for quite a while. Wrote my first KeyLogger in 2007 using the relatively new OnEvent> function. That particular script had a separate subroutine for each letter. I don't recall when I rewrote it using one subroutine and a fifth onevent parameter but it was not long after. I remediated the jump-to-top issue with a flag variable at the start of the script. If>BlahVar=1,Loop this jumped from the top of the script to my idle loop. That way we skipped over the onevents so they didn't get loaded over and over with each key press. Just put a Let>Blahvar=1 at the end of the onevent block. A bigger issue for me at that time was keeping the keystrokes limited. Touching a letter key quickly would produce ten or more copies of that letter. The idle loop can be used to control the repeats but timing is difficult. Too fast and you still get multiples, too slow and you miss the next letter from a fast typer.

In any case here is a much more reliable method. Still has its issues. I wrote this as a novelty years ago but did not post it for not wanting to post a keylogging script. Today I think keyloggers are the least of our security concerns. This uses the OnKeyPress dialog event. Then as a demo writes the key presses to a Macro Scheduler message box. The key presses need to be typed onto the dialog, so the script will create a monster, invisible, stayontop dialog. The script times out after 30 seconds but can be closed sooner by picking the "X" to close the message box.

If nothing else I hope this is a pleasant diversion for your always active mind.

Dick



Code: Select all

//Max workable setting = 23171
Let>vDim=23170
Let>onceFlag=1
Message>A message to be edited (sort of)
Wait>0.3

Dialog>Dialog1
object Dialog1: TForm
  BorderStyle = bsNone
  Caption = 'Custo-Changio'
  AlphaBlend = True
  AlphaBlendValue = 0
  Position = poScreenCenter
  FormStyle = fsStayOnTop
end
EndDialog>Dialog1

SetDialogProperty>Dialog1,,ClientHeight,vDim
SetDialogProperty>Dialog1,,ClientWidth,vDim
AddDialogHandler>Dialog1,,OnKeyPress,SUBROUTINE_NAME

Show>Dialog1

GetControlText>Macro Scheduler Message,TMemo,1,vPhrase
VbEval>timer,StartTime
Label>TimeLoop
  Wait>0.01
  MoveWindow>Custo-Changio,-2000,-2000
  VbEval>timer-%StartTime%,TotalTime
  If>TotalTime>30
    CloseWindow>Macro Scheduler Message
  EndIf
  IfWindowOpen>Macro Scheduler Message
  Else
    Exit>0
  EndIf
Goto>TimeLoop

SRT>SUBROUTINE_NAME
  If>SUBROUTINE_NAME_Key=8
    Length>vPhrase,vLen
    If>vLen>0
      Sub>vLen,1
      Midstr>vPhrase,1,vLen,vPhrase
    EndIf
  Else
  If>SUBROUTINE_NAME_Key=13
    Let>vPhrase=%vPhrase%%crlf%
  Else
    VBEval>Chr(%SUBROUTINE_NAME_Key%),vKeyPressRes
    Let>vPhrase=%vPhrase%%vKeyPressRes%
  EndIf
  EndIf
  SetControlText>Macro Scheduler Message,TMemo,1,%vPhrase% - %SUBROUTINE_NAME_Key%
END>SUBROUTINE_NAME

User avatar
Grovkillen
Automation Wizard
Posts: 1024
Joined: Fri Aug 10, 2012 2:38 pm
Location: Bräcke, Sweden
Contact:

Re: Variables when calling SRT from OnEvent

Post by Grovkillen » Thu Aug 24, 2023 10:33 am

I imagine the KEY_UP event could be used to only capture one key at the time:

Code: Select all

//trigger the up
OnEvent>KEY_DOWN,VK72,0,SET_THE_VARIABLE_TO_UP
//trigger all the time but the variable check makes it only trigger once per down
OnEvent>KEY_UP,VK72,0,TRIGGER_AFTER_KEY_IS_RELEASED
//ESC=close app
OnEvent>KEY_DOWN,VK27,0,CLOSE_APP
Label>RESTART_LOOP
Wait>0.02
Goto>RESTART_LOOP
SRT>CLOSE_APP
  Exit>
END>CLOSE_APP
SRT>SET_THE_VARIABLE_TO_UP
  Let>KEY_UP=1
END>SET_THE_VARIABLE_TO_UP
SRT>TRIGGER_AFTER_KEY_IS_RELEASED
  If>KEY_UP=1
    Let>KEY_UP=0
    **BREAKPOINT**
  Endif>
END>TRIGGER_AFTER_KEY_IS_RELEASED
But yeah, I have a SRT per key now because of this bug. The variable check you mentioned isn't working for me, I've tried it. Thanks anyways :)
Let>ME=%Script%

Running: 15.0.24
version history

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts