Sign in to follow this  
Followers 0
FeliXXL

First time working with "_WinAPI_GetModuleHandle"

5 posts in this topic

Hey there.

I posted a slightly shortened version of my code below:

#include <WinAPI.au3>
#include <WindowsConstants.au3>

Global $g_hHook, $g_hStub_KeyProc = ""

Test()

Func Test()
   OnAutoItExitRegister("CleanUp")

   Local $hMod

   $g_hStub_KeyProc = DllCallbackRegister("_KeyProc", "Int", "int;wparam;lparam")
   $hMod = _WinAPI_GetModuleHandle(0)
   $g_hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($g_hStub_KeyProc), $hMod)

   While 1
      Sleep(100)
   WEnd
EndFunc

Func _KeyProc($nCode, $wParam, $lParam)
   Local $tKEYHOOKS
   $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)

   If $wParam = $WM_KEYDOWN Then
      KeyValue(DllStructGetData($tKEYHOOKS, "vkCode"))
   EndIf
   Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
EndFunc

Func KeyValue($iKeycode)
   If ($iKeycode = 112) Then
      ;do stuff if F1 has been pressed
   ElseIf ($iKeycode = 117) Then
      Exit ;exit if F6 has been pressed
   EndIf
EndFunc

Func CleanUp()
    _WinAPI_UnhookWindowsHookEx($g_hHook)
    DllCallbackFree($g_hStub_KeyProc)
EndFunc

Now my question...

The ";do suff if F1 has been pressed" is a placeholder...

Normally i put in "Send("text")" to try it out. And this works just fine.

But if i do put in "Send("This is a very long message, so i dont want to type it all by myself")"

he only writes it down the first 6 times i press "F1" (($iKeycode = 112))...

I cannot imagine any possible way to fix that, so i thought you might be able to help me out of that misery.

Greetings

FeliXXL

Share this post


Link to post
Share on other sites



Seeing as I can't replicate your issue, I can only suggest you use _IsPressed() or HotKeySet(), which kind of make more sense in this situation anyway.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Alright... I did not believe it too, so i made a video, just to clearify what i meant...

Edited by FeliXXL

Share this post


Link to post
Share on other sites

Alright, i did some testing and have got some news...

If my string i send is under 30 characters it does exactly everything as expected.

If it is more than 30 characters it struggles and only lets me execute it 6 times...

Now i tested running it x64 (instead of x32 previously) and it works fine.

I still want it to be able to run on 32 bit machines though.

Any suggestions on how to achieve it without doing a "dirty hack" like splitting every string up in 30 character-chunks and sending em one after another?

Greetings

FeliXXL

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Your video was a good idea to post here. Go to your script window and click f5 (this will run your opened script) and open notepad and don't maximize the window (You want to see the console in Scite). Add a @CR at the end of your text insertion. This works for me more than 10 times on windows 7 x64 (I had to change the F1 to F2 because I have the help menu popping up with F1):

#include <WinAPI.au3>
#include <WindowsConstants.au3>

Global $g_hHook, $g_hStub_KeyProc = ""

Test()

Func Test()
   OnAutoItExitRegister("CleanUp")

   Local $hMod

   $g_hStub_KeyProc = DllCallbackRegister("_KeyProc", "Int", "int;wparam;lparam")
   $hMod = _WinAPI_GetModuleHandle(0)
   $g_hHook = _WinAPI_SetWindowsHookEx($WH_KEYBOARD_LL, DllCallbackGetPtr($g_hStub_KeyProc), $hMod)

   While 1
      Sleep(100)
   WEnd
EndFunc

Func _KeyProc($nCode, $wParam, $lParam)
   Local $tKEYHOOKS
   $tKEYHOOKS = DllStructCreate($tagKBDLLHOOKSTRUCT, $lParam)

   If $wParam = $WM_KEYDOWN Then
      KeyValue(DllStructGetData($tKEYHOOKS, "vkCode"))
   EndIf
   Return _WinAPI_CallNextHookEx($g_hHook, $nCode, $wParam, $lParam)
EndFunc

Func KeyValue($iKeycode)
   If ($iKeycode = 113) Then
      send("This is a really long bit of text I dont want to type manually" & @CR)
   ElseIf ($iKeycode = 117) Then
      Exit ;exit if F6 has been pressed
   EndIf
EndFunc

Func CleanUp()
    _WinAPI_UnhookWindowsHookEx($g_hHook)
    DllCallbackFree($g_hStub_KeyProc)
EndFunc

Look in the console window below your code in the scite window for an error to occur when your script stops working. 

Edited by computergroove
1 person likes this

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

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  
Followers 0