Jump to content
Sign in to follow this  
flyfishermedic

Autotext

Recommended Posts

flyfishermedic

Hi,

Programming in VB.NET

I have tried to look for an answer to this in the forums, and have used the DLL in the past for a numbver of things, and found it very useful. In psudotext this is what I would like to do.

1 Monitor all running windows/applications.

2 When a certain text string is entered - e.g. scr$ substitute an alternative text string - e.g. 'This is my alternative text string'.

I will have quite a number of text strings - ideally perahps a couple of hundred that I need to look out for an substitute.

I think the main thing that I probably need the autoit DLL to do is to be monitoring all Windows for the series of keystrokes.

Any pointers to how to do this please??

Paul Bromley

Share this post


Link to post
Share on other sites
Paulie

Maybe a Hotstring could help you:

#include <DllCallBack.au3> 
 
Global Const $WH_KEYBOARD_LL = 13 
Global $hHook, $pStub_KeyProc 
Global $pStub_KeyProc = _DllCallBack ("_KeyProc","int;ptr;ptr") 
Global $hmod = DllCall("kernel32.dll","hwnd","GetModuleHandle","ptr",0) 
Global $hHook = DllCall("user32.dll","hwnd","SetWindowsHookEx","int", _ 
            $WH_KEYBOARD_LL,"ptr",$pStub_KeyProc,"hwnd",$hmod[0],"dword",0) 
Global $buffer = "" 
 
MsgBox(4096,"","Type anything anywhere and it will appear in the top left corner of the screen." & @CRLF & "Type die to quit") 
 
While 1 
    Sleep(10) 
WEnd 
 
Func EvaluateKey($keycode, $flags) 
     ;$buffer &= "[" & Hex($flags) & "]" 
     If BitAND($flags, 16) Then Return 
    If (($keycode > 22) And ($keycode < 91)) _ 
        Or (($keycode > 47) And ($keycode < 58)) Then 
        $buffer &= Chr($keycode) 
        ToolTip($buffer,0,0) 
    ElseIf ($keycode > 159) And ($keycode < 164) Then 
        Return 
    EndIf 
     If StringRight($buffer, 3) = "die" Then Exit 
EndFunc 
 
Func _KeyProc($nCode, $wParam, $lParam) 
    Local $ret,$KEYHOOKSTRUCT 
    If $nCode < 0 Then 
        $ret = DllCall("user32.dll","long","CallNextHookEx","hwnd",$hHook[0], _ 
                        "int",$nCode,"ptr",$wParam,"ptr",$lParam) 
        Return $ret[0] 
    EndIf 
    If $wparam = 256 Then 
        $KEYHOOKSTRUCT = DllStructCreate("dword;dword;dword;dword;ptr",$lParam) 
        EvaluateKey(DllStructGetData($KEYHOOKSTRUCT,1), DllStructGetData($KEYHOOKSTRUCT, 3)) 
    EndIf 
    $ret = DllCall("user32.dll","long","CallNextHookEx","hwnd",$hHook[0], _ 
                    "int",$nCode,"ptr",$wParam,"ptr",$lParam) 
    Return $ret[0] 
EndFunc 
 
Func OnAutoItExit() 
    DllCall("user32.dll","int","UnhookWindowsHookEx","hwnd",$hHook[0]) 
EndFunc

Share this post


Link to post
Share on other sites
Richard Robertson

Paul, that code is for regular AutoIt, not the COM version.

Edited by Richard Robertson

Share this post


Link to post
Share on other sites
Paulie

Paul, that code is for regular AutoIt, not the COM version.

Yeah.. i probably should have mentioned that..

but regardless, it could solve your question!

Share this post


Link to post
Share on other sites
flyfishermedic

Shame that is exactly what I wanted to do, but within VB.NET. I see there is some talk of the dll being updated??

Is there anyway using the dll that I can get it to listen to just one window for one of a number of textstrings??

Paul Bromley

Yeah.. i probably should have mentioned that..

but regardless, it could solve your question!

Share this post


Link to post
Share on other sites
Richard Robertson

Actually, I have a solution. Have you been to CodeProject.com? They recently ran an article about mouse and keyboard hooks.

http://www.codeproject.com/KB/dotnet/globa...eyboardlib.aspx

This is for C# but if you know how to translate it (or at least compile and reference it in your VB.Net project) then you can get keyboard hooks. The code Paul showed you uses keyboard hooks but in a slightly messy way.

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.