Jump to content

Block keyboard input without admin rights


Recommended Posts

3 hours ago, JockoDundee said:

I’ll look for runparamsdialog.au3 and see if I can jam my stuff in there.

If your code should be in "RunParamsDialog.au3", you might need a communication between VBScript and AutoIt. It might look like the blue lines of code in the following spoiler. (Thanks to LarsJ for the VBScript-AutoIt communication!)

Spoiler

  - "...\<Pau3>\Script\VBScript\AutoIt3_CompRun_LogWin.vbs"

     Line 498 - ... :
      ===============

      If bLogWinCloseDelayed = True And logIsVisible() = True Then

        ' Delay of 3 seconds before the LogWin is closed.
        AutoIt3___Base.WaitForMilliSecs(sLogWinAutoCloseDelay * 1000) ' sec to ms

        If g_bStopLogWinAutoClose = False Then
          If CompilerRunnerIsRunning() = False Then

            On Error resume next ' So that 'oCOM_DictRunPrmsDlg.Item("DoBlockInput") = False' is also executed if errors occur.
            Dim oCOM_DictRunPrmsDlg

            Set oCOM_DictRunPrmsDlg = GetObject(gc_sCOM_ROT_Name_CallTipVwr)

            oCOM_DictRunPrmsDlg.Item("DoBlockInput") = True

            sLastActiveWinHwnd = AutoIt3___Base.ExecuteAu3Line("WinGetHandle('[active]')", "/WaitForResult")
            sLastActiveWinTitle = AutoIt3___Base.ExecuteAu3Line("WinGetTitle(HWND('" & sLastActiveWinHwnd & "'))", "/WaitForResult")

            ' This is the most relevant place:
            ' --------------------------------
            '   This is where the LogWin is closed ("LogWin_Hide()"), which briefly puts the
            '   input focus on PSPad's editor and allows a few characters to end up there.

            LogWin_Hide() 

            If sLastActiveWinTitle = gc_sRunParamsDlgTitle Then
              ' As soon as possible the focus will be back on the RunParamsDialog.
              Call AutoIt3___Base.ExecuteAu3Line("WinActivate(HWND('" & sLastActiveWinHwnd & "'))", "")
            End If

            oCOM_DictRunPrmsDlg.Item("DoBlockInput") = False

          End If
        End If

      End If ' If bLogWinCloseDelayed = True And logIsVisible() = True

 

In "...\<Pau3>\PSPad4Au3\Au3 scripts\RunParamsDialog.au3" exists already a COM ROT Dict. There you can simply access the item, e.g.

If $g_oDict_COM_RunPrmsDlg.Exists("DoBlockInput") Then
  If oCOM_DictRunPrmsDlg.Item("DoBlockInput") = False Then
...

Edited by Professor_Bernd
Link to comment
Share on other sites

7 hours ago, Professor_Bernd said:

you might need a communication between VBScript and AutoIt

I hope to hell not :)

here's the modified RunParamsDialog.au3 below:

There are 4 added sections / no deletions.  added sections marked by ;Jocko Add

had to add a global variable for the edit control.

not doing any VB work.  I don't need it.  Unless its doing crazy shit, it shouldn't bother me.

not tested.

Odds for expectation setting:(overlap allowed)

  • 20% chance of doing nothing
  • 15% chance of crashing on startup
  • 30% chance of crashing while running
  • 25% chance of hanging
  • 5%   chance of hanging (requiring reboot)
  • 40% chance of doing "something"
  • 20% chance of "working"
  • 10% chance of actually working in a way that solves the problem

 

 

RunParamsDialog.au3

Code hard, but don’t hard code...

Link to comment
Share on other sites

I have tested your code extensively and replaced one line. Unfortunately, nothing has changed: In the brief moment of focus change, characters still end up in the PSPad editor.

;;;;;;;;;;;;;;Jocko Add;;;;;;;;;;;;;;;;;;;;;;
Func FocusChange($hWnd, $iMsg, $wParam, $lParam)
  #forceref $hWnd, $iMsg, $wParam, $lParam

If $wParam Then
   SetKeys(True)
Else
;     If WinGetHandle("[ACTIVE]")=WinGetHandle("[CLASS:Notepad]") Then
    If _WinAPI_GetClassName(WinGetHandle("[ACTIVE]")) = "TfPSPad" Then ; <==
       WinActivate($hWnd)
    Else
       SetKeys(False)
    EndIf
EndIf

Return $GUI_RUNDEFMSG

EndFunc

I also did tests with BlockInputEX from Nine, also without success.

My guess is the delay within the communication in PSPad between Delphi, VBScript, WSH and AutoIt. Therefore I thought of a workaround: The LogWin AutoClose calls in VBScript the PSPad internal command to close the LogWin. So I use another PSPad-internal command at the same place and switch the file in the editor to read-only. Then AutoClose is called and when RunParamsDialog has the focus again, the file is switched writable in the editor.

That works for now. Maybe later with UIAutomation another solution can be found.

Thank you very much for your effort! :)

Link to comment
Share on other sites

17 minutes ago, Professor_Bernd said:

Unfortunately, nothing has changed: In the brief moment of focus change, characters still end up in the PSPad editor.

But the dialog window still works ok?

Its not a problem of delay - the dialog window remaps all the keys when it starts, just so nothing can get any keystrokes unless the dialog window says so.

maybe vbscript is messing with the focus at the same time?

Code hard, but don’t hard code...

Link to comment
Share on other sites

14 minutes ago, JockoDundee said:

But the dialog window still works ok?

Its not a problem of delay - the dialog window remaps all the keys when it starts, just so nothing can get any keystrokes unless the dialog window says so.

I can't tell exactly if we mean the same thing, so I'll try to explain it this way: I don't notice any difference at all. When I start RunParamsDialog, I can click on it and write in it. When I click into the editor of PSPad, the editor gets the focus and I can write there. Nothing is redirected.

Sorry I can't explain it better. Can you understand what I mean?

Link to comment
Share on other sites

i downloaded pspad, and loaded helloworld.au3, should f5 run it, or do i need to do something else to configure pspad for autoit?  I see no run - parameters option when i right click in the right pane.

Code hard, but don’t hard code...

Link to comment
Share on other sites

You don't have to prepare anything, just start PSPad and open "Hello World.au3" in PSPad. PSPad is specially prepared for AutoIt. When you press F5, the script should be executed. The Hello World MsgBox should appear and the AutoIt output appears in the LogWin.

To use tools from the right panel, just double click on them.

If nothing happens with F5, maybe your WSH is disabled?

Link to comment
Share on other sites

I just downloaded the test version myself and it works fine for me. The zip archive has a long name. If you unzipped in a deep path, copy only the "PSPad4AutoIt3" folder and "Hello world.au3" into a shorter path and try it there.

Edited by Professor_Bernd
Link to comment
Share on other sites

I just tested it and under test conditions it worked 10 times out of 10!

Did I see that correctly, that you just added a delay? To compensate for the delay between programming languages?

I will test it in real use in the near future, which may take some time.

Thanks for your effort, good job! 👍

 

Link to comment
Share on other sites

3 hours ago, Professor_Bernd said:

I just tested it and under test conditions it worked 10 times out of 10!

Yikes! I’d say stop now while you’re ahead :)

3 hours ago, Professor_Bernd said:

Did I see that correctly, that you just added a delay? To compensate for the delay between programming languages?

Although I briefly considered a Intralingual  Compensatory Delay, I ultimately rejected an ICD on the basis of excessive and gratuitous novelty.

Rather the delay compensates for a lack of actionable knowledge; by reaching ever so slightly into the time domain; and using the datapoint gained as my heuristical talisman, if you will.

Plainly speaking what this means is that whenever the Param window becomes the fg window, it wastes no time in remapping most keystrokes, globally, to its own handler.  Which works great until the window loses focus! So then it says “who did I lose focus to?” If the new fg window is neither the param window nor the edit window, then it hastily removes its own handler to get out if the way.  Otherwise, based on the theory that if the reason we lost focus was because the F5 was pressed and the log stole it, that the focus will be restored by VB in a few milliseconds.  If after a few milliseconds this doesn’t happen, we hastily remove the handler, assuming that the focus was actually changed by a click to the edit window.

Hope that makes more sense to you than it does to me :)

 

Code hard, but don’t hard code...

Link to comment
Share on other sites

English is not my native language. I hope that I have nevertheless grasped the meaning correctly and that when I look for the plans for ICD (Intralingual Compensatory Delay), I find them directly above the drawer with the plans for the flux capacitor. ;)

51 minutes ago, JockoDundee said:

Hope that makes more sense to you than it does to me :)

I ... um, ... yeah, sure, sure, makes sense, :sweating: I guess. I'll have to think about it some more, but it sounds good.

Ok, now seriously, that was good work! Whether the timing will work on other PCs remains to be seen. I thank you!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...