Jump to content



Photo

Translate AHK to AU3


  • Please log in to reply
22 replies to this topic

#1 delray

delray

    Seeker

  • Active Members
  • 31 posts

Posted 19 February 2012 - 02:52 PM

These 2 pieces of code are AHK; what is the AU3 equivalent is:
DetectHiddenWindows, On NumPut( WinExist( A_ScriptFullPath " ahk_class AutoHotkey ahk_pid " PID),NID,4 ) DetectHiddenWindows, Off

The main problem with the following is the ":" between operations:
  IC := RC=0&&WC=0 ? 1 : RC!=0&&WC=0 ? 2 : RC=0&&WC!=0 ? 3 : RC!=0&&WC!=0 ? 4 : NumPut( hIcon%IC%,NID,20 )








#2 BrewManNH

BrewManNH

    באָבקעס מיט קודוצ׳ה

  • MVPs
  • 6,877 posts

Posted 19 February 2012 - 03:31 PM

When posting code from another language, it might be best to include descriptions of what every command does. Unless someone is coding in both languages, we'd have no idea what those commands do or their format if we're able to guess what the commands do but not what the parameters are.

You're basically asking a small minority of people to help you because AHK and AutoIt3 don't use the same syntax and few common commands, unless you expect someone to learn what those commands do and how the parameters are supposed to work to help you.

How to ask questions the smart way!

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.

Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.

_FileGetProperty - Retrieve the properties of a file SciTE Toolbar - A toolbar demo for use with the SciTE editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.

GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips.

Posted Image


#3 delray

delray

    Seeker

  • Active Members
  • 31 posts

Posted 19 February 2012 - 03:33 PM

Sorry I asked.

#4 BrewManNH

BrewManNH

    באָבקעס מיט קודוצ׳ה

  • MVPs
  • 6,877 posts

Posted 19 February 2012 - 03:42 PM

Sorry I asked.

I wasn't insulting you, I was asking you to supply more information so that we would be able to help you. As it stands, as I said above, there's a small minority of forum users that would use both languages so you're not going to get many able to help without you helping yourself by supplying that information.

How to ask questions the smart way!

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.

Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.

_FileGetProperty - Retrieve the properties of a file SciTE Toolbar - A toolbar demo for use with the SciTE editorGUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.

GUIToolTip UDF Demo - Demo script to show how to use the GUIToolTip UDF to create and use customized tooltips.

Posted Image


#5 delray

delray

    Seeker

  • Active Members
  • 31 posts

Posted 19 February 2012 - 04:27 PM

The code is part of a larger program all written in AHK which I am trying to translate myself so I can understand it. I look for answers in AHK and AU3 help files and didn't find an answer. I have finally translated the second part:
If $RC=0 And $WC=0 Then $IC=1 ElseIf $RC<>0 And $WC=0 Then $IC=2 ElseIf $RC=0 And $WC<>0 Then $IC=3 ElseIf $RC<>0 and $WC<>0 Then $IC=4 EndIf

Here is the AHK explanation of the second part:
DetectHiddenWindows, On = Determines whether invisible windows are "seen" by the script. NumPut( WinExist( A_ScriptFullPath " ahk_class AutoHotkey ahk_pid " PID),NID,4 ) NumPut = Stores number in an array A_ScriptFullPath = The combination of the above two variables to give the complete file specification of the script, e.g. C:\My Documents\My Script.ahk ahk_class AutoHotkey = All windowing commands can operate upon a class of windows by the class text shown by Window Spy or retrieved by WinGetClass. In the following example, a split-view Explorer window would be activated: WinActivate ahk_class ExploreWClass ahk_pid = All windowing commands can operate upon the window(s) belonging a process identifier (PID). For example, WinClose ahk_pid %VarContainingPID% would close the topmost window of that process. A PID can be retrieved via WinGet or Run or Process. DetectHiddenWindows, Off = Determines whether visible windows are "seen" by the script.

Hopefully this is a little help.

#6 delray

delray

    Seeker

  • Active Members
  • 31 posts

Posted 19 February 2012 - 06:42 PM

Here is the code I have come up with. The idea is to set an icon into the tray depending on its current status idle/read/write/read+write. The only problem is that it fails. Any and all help appreciated.
Plain Text         
#include <Process.au3> ;#Include <Timers.au3> Global $NID[444], $Ret, $nReturn Global $ORC=0, $OWC=0, $DP[88] main() Func main() ProcessSetPriority("HHD_Monitor.au3", 4) $PID = DllCall("kernel32.dll", "handle", "GetCurrentProcessId") ; Run, diskperf.exe -y   ; Execute it once to enable Disk Performance monitoring. ; DISK_PERFORMANCE $hDrv = DllCall("kernel32.dll", "ptr", "CreateFile", "Str", "\\.\PhysicalDrive0", "uint", 0, "uint", 3, "uint", 0, "uint", 3, "uint", 0, "uint", 0) While 1 ;_Timer_SetTimer(HDD_Monitor) ;HDD_Monitor:   $Ret =   DllCall("kernel32.dll", "int", "DeviceIoControl", "uint", 0x70020, "uint", DllStructGetPtr($DP), "uint", 88, "uint_ptr", $nReturn, "uint", 0)   $NRC = $DP[40] ;NRC:=NumGet(DP,40),   $NWC = $DP[44] ;NWC:=NumGet(DP,44),   $RC = $NRC - $ORC ;RC:=NRC-ORC,   $WC = $NWC - $OWC ;WC:=NWC-OWC,   $ORC = $NRC ;   $ORC = $NRC ;ORC:=NRC,   $OWC = $NWC ;OWC:=NWC   If $RC=0 And $WC=0 Then   ; $IC=1    TraySetIcon("0.icon")   ElseIf $RC<>0 And $WC=0 Then   ; $IC=2    TraySetIcon("1.icon")   ElseIf $RC=0 And $WC<>0 Then   ; $IC=3    TraySetIcon("2.icon")   ElseIf $RC<>0 and $WC<>0 Then   ; $IC=4    TraySetIcon("3.icon")   EndIf WEnd EndFunc


#7 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 19 February 2012 - 10:02 PM

The main problem with the following is the ":" between operations:

  IC := RC=0&&WC=0 ? 1 : RC!=0&&WC=0 ? 2 : RC=0&&WC!=0 ? 3 : RC!=0&&WC!=0 ? 4 : NumPut( hIcon%IC%,NID,20 )

What does ":", ":=", "&&" mean in AHK language?

#8 water

water

    ?

  • MVPs
  • 10,709 posts

Posted 19 February 2012 - 10:17 PM

&& is the logical-AND operator
:= is the Assign operator
according to this docu site.

":" seems to be like "elseif" in AutoIt.

Edited by water, 19 February 2012 - 10:24 PM.

UDFs:

Active Directory (2012-10-12 - Version 1.3.0.0 released) - Download - General Help & Support - Example Scripts - Wiki

OutlookEX (2012-10-07 - Version 0.9.0.0 released) - Download - General Help & Support - Example Scripts - Wiki

ExcelChart (2013-01-21 - Version 0.3.1.1 released) - Download - General Help & Support - Example Scripts

WordEX (2012-12-29 - Version 1.3 released) - Download

ExcelEX (2013-05-11 - Alpha 4 released) - Download


#9 delray

delray

    Seeker

  • Active Members
  • 31 posts

Posted 19 February 2012 - 10:18 PM

What does ":", ":=", "&&" mean in AHK language?

  If $RC=0 And $WC=0 Then   ; $IC=_    TraySetIcon("Drive.ico")   ElseIf $RC<>0 And $WC=0 Then   ; $IC=2    TraySetIcon("Read.ico")   ElseIf $RC=0 And $WC<>0 Then   ; $IC=3    TraySetIcon("Write.ico")   ElseIf $RC<>0 and $WC<>0 Then   ; $IC=4    TraySetIcon("Read_Write.ico")   EndIf


Found part of the problem, but need an answer: http://www.autoitscript.com/forum/topic/...andle-via-createfile/page__fro

#10 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 19 February 2012 - 11:30 PM

Heres just a few things that stood out to me after really looking at it. First you dont have to use a dllcall to get the PID. Just use the @AutoItPID

Next is the other dllcall posted below. I belive its wrong for a few reasons:
  • DllstructGetPtr() returns a ptr to a Dll Structure created with DllStructCreate()
  • Going by the what I read on the msdn I think your missing some parameters.
  • $nReturn variable cant be used the way your trying. I'm pretty sure that would need to be another dll structure.
Global $NID[444], $Ret, $nReturn Global $ORC = 0, $OWC = 0, $DP[88] $Ret = DllCall("kernel32.dll", "int", "DeviceIoControl", _                                                   "uint", 0x70020, _ ;             hDevice [in]                                                   "uint", DllStructGetPtr($DP), _; dwIoControlCode [in]                                                   "uint", 88, _;                  lpInBuffer [in, optional]                                                   "uint_ptr", $nReturn, _;      nInBufferSize [in]                                                   "uint", 0);                        lpOutBuffer [out, optional]                                                   ;??????                          nOutBufferSize [in]                                                   ;??????                          lpBytesReturned [out, optional]                                                   ;??????                          lpOverlapped [in, out, optional]

Edited by Beege, 19 February 2012 - 11:45 PM.


#11 delray

delray

    Seeker

  • Active Members
  • 31 posts

Posted 19 February 2012 - 11:46 PM

Heres just a few things that stood out to me after really looking at it. First you dont have to use a dllcall to get the PID. Just use the @AutoItPID

Next is the other dllcall posted below. I belive its wrong for a few reasons:

  • DllstructGetPtr() returns a ptr to a Dll Structure created with DllStructCreate()
  • Going by the what I read on the msdn I think your missing some parameters.
  • $nReturn variable cant be used the way your trying. I'm pretty sure that would need to be another dll structure.
Global $NID[444], $Ret, $nReturn Global $ORC = 0, $OWC = 0, $DP[88] $Ret = DllCall("kernel32.dll", "int", "DeviceIoControl", _                                                   "uint", 0x70020, _ ;        hDevice [in]                                                   "uint", DllStructGetPtr($DP), _; dwIoControlCode [in]                                                   "uint", 88, _;                    lpInBuffer [in, optional]                                                   "uint_ptr", $nReturn, _;      nInBufferSize [in]                                                   "uint", 0);                        lpOutBuffer [out, optional]                                                   ;??????                          nOutBufferSize [in]                                                   ;??????                          lpBytesReturned [out, optional]                                                   ;??????                          lpOverlapped [in, out, optional]

This is what I currently have:
#include <WinAPI.au3> #include <WinAPIEx.au3> Local $tDGEX[444] Local $hDrv = _WinAPI_CreateFile( "\\.\PhysicalDrive0", 2, 3, 0, 3, 0) MsgBox(0, 0, $hDrv) ; Returns handle Local $ret = DllCall('kernel32.dll', 'int', 'DeviceIoControl', _            'ptr', $hDrv, _            'dword', 0x70020, _            'ptr', 0, _            'dword', 0, _            'ptr', ptr($tDGEX), _            'dword', 88, _            'dword*', 0, _            'ptr', 0) MsgBox(0, 0, $ret) ; Returns null


#12 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 19 February 2012 - 11:54 PM

DllCall() alway returns an array unless an error happened. Whats the outcome if you change your msgbox to this:
If @error Then      MsgBox(0,0,'error = ' & @error) Else      MsgBox(0, 0, $ret[0]) EndIf


Edit: Also if $ret[0] = 0 you can further debug the problem by calling _WinAPI_GetLastError()
If @error Then      MsgBox(0,0,'error = ' & @error) Else      If Not $ret[0] then           MsgBox(0,'WinApi Error', _WinAPI_GetLastError())      Else           MsgBox(0, 0, $ret[0])      EndIf EndIf

Edited by Beege, 20 February 2012 - 12:00 AM.


#13 delray

delray

    Seeker

  • Active Members
  • 31 posts

Posted 20 February 2012 - 12:10 AM

Edit: Also if $ret[0] = 0 you can further debug the problem by calling _WinAPI_GetLastError()

If @error Then      MsgBox(0,0,'error = ' & @error) Else      If Not $ret[0] then           MsgBox(0,'WinApi Error', _WinAPI_GetLastError())      Else           MsgBox(0, 0, $ret[0])      EndIf EndIf

$ret[0] = 0
_WinAPI_GetLastError()) = 122 System buffer too small... What ever that means.

Edited by delray, 20 February 2012 - 12:15 AM.


#14 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 20 February 2012 - 12:16 AM

Sorry I should have put _WinAPI_GetLastErrorMessage() and not _WinAPI_GetLastError().

And whats the value your getting from MsgBox(0, 0, $hDrv) ; Returns handle ??

I just ran this and mine did not return a handle. It returned 0, which is a failure..

#15 delray

delray

    Seeker

  • Active Members
  • 31 posts

Posted 20 February 2012 - 12:27 AM

Sorry I should have put _WinAPI_GetLastErrorMessage() and not _WinAPI_GetLastError().

And whats the value your getting from MsgBox(0, 0, $hDrv) ; Returns handle ??

I just ran this and mine did not return a handle. It returned 0, which is a failure..


WinApi Error: The data area passed to a system call is too small.

$hDrv = 0x00000170

Don't be sorry, I am grateful.

#16 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 20 February 2012 - 12:36 AM

Ok make these changes:
Local $tDGEX = DllStructCreate("byte[444]"); not sure what the real size should be..


And in the DllCall().
Local $ret = DllCall('kernel32.dll', 'int', 'DeviceIoControl', _            'ptr', $hDrv, _            'dword', 0x70020, _            'ptr', 0, _            'dword', 0, _            'ptr', DllStructGetPtr($tDGEX), _; Ptr to dllstructure.            'dword', 88, _            'dword*', 0, _            'ptr', 0)


Also note that ptr() function is to more or less change a integer value into a ptr value. Not to get a ptr to a variable.

Edited by Beege, 20 February 2012 - 12:37 AM.


#17 delray

delray

    Seeker

  • Active Members
  • 31 posts

Posted 20 February 2012 - 12:48 AM

Ok make these changes:

Local $tDGEX = DllStructCreate("byte[444]"); not sure what the real size should be..

And in the DllCall().
Local $ret = DllCall('kernel32.dll', 'int', 'DeviceIoControl', _            'ptr', $hDrv, _            'dword', 0x70020, _            'ptr', 0, _            'dword', 0, _            'ptr', DllStructGetPtr($tDGEX), _; Ptr to dllstructure.            'dword', 88, _            'dword*', 0, _            'ptr', 0)

Also note that ptr() function is to more or less change a integer value into a ptr value. Not to get a ptr to a variable.

That made the difference. No error and $ret[0] = 1

Now I will try and move to the next step which will take a few minutes. Thanks again Mass Spammer...

#18 delray

delray

    Seeker

  • Active Members
  • 31 posts

Posted 20 February 2012 - 01:02 AM

Here is the entire code and I am not getting any data in $NRC and $NWC:
Plain Text         
#include <Process.au3> #include <array.au3> #include <WinAPIEx.au3> Global $NID[444], $Ret, $nReturn, $hDrv Global $ORC=0, $OWC=0 main() Func main() Global $DP = DllStructCreate("byte[88]") Global $hDrv = _WinAPI_CreateFile( "\\.\PhysicalDrive0", 2, 3, 0, 3, 0) While 1 Local $ret = DllCall('kernel32.dll',  'int', 'DeviceIoControl', _            'ptr', $hDrv, _            'dword', 0x70020, _            'ptr', 0, _            'dword', 0, _            'ptr', DllStructGetPtr($DP), _            'dword', 88, _            'dword*', 0, _            'ptr', 0) ;ToolTip($hDrv & " : " & $ret[0])   $NRC = DllStructGetData ($DP, 40) ;NRC:=NumGet(DP,40),   $NWC = DllStructGetData ($DP, 44) ;NWC:=NumGet(DP,44),   $RC = $NRC - $ORC ;RC:=NRC-ORC,   $WC = $NWC - $OWC ;WC:=NWC-OWC,   $ORC = $NRC ;   $ORC = $NRC ;ORC:=NRC,   $OWC = $NWC ;OWC:=NWC ToolTip($NRC & " : " & $NWC)   ; 0 : 0 at this point   Sleep(500) If $RC=0 And $WC=0 Then   ; $IC=_    TraySetIcon("Drive.ico")   ElseIf $RC<>0 And $WC=0 Then   ; $IC=2    TraySetIcon("Read.ico")   ElseIf $RC=0 And $WC<>0 Then   ; $IC=3    TraySetIcon("Write.ico")   ElseIf $RC<>0 and $WC<>0 Then   ; $IC=4    TraySetIcon("Read_Write.ico")   EndIf WEnd EndFunc


#19 Beege

Beege

    Universalist

  • MVPs
  • 843 posts

Posted 20 February 2012 - 01:14 AM

Im assuming your trying to get elements 40 and 44 from the array? You only have 1 element in the dll structure and that element is byte[88]. Since the element is an array itself, you need to use the 3rd parameter to access the elements of that array. Try:
  $NRC = DllStructGetData ($DP, 1, 40) ;NRC:=NumGet(DP,40) $NWC = DllStructGetData ($DP, 1, 44) ;NWC:=NumGet(DP,44),


edit: million typos

Edited by Beege, 20 February 2012 - 01:16 AM.


#20 delray

delray

    Seeker

  • Active Members
  • 31 posts

Posted 20 February 2012 - 01:59 AM

I sent the output to num and caps lock and they are fluctuating as they should be, but the icons are not activating other than the first one (Drive.ico).
Plain Text         
#include <Process.au3> #include <array.au3> #include <WinAPIEx.au3> Global $NID[444], $Ret, $nReturn, $hDrv Global $ORC=0, $OWC=0 Global $DP = DllStructCreate("byte[88]") Global $hDrv = _WinAPI_CreateFile( "\\.\PhysicalDrive0", 2, 3, 0, 3, 0) While 1 Local $ret = DllCall('kernel32.dll',  'int', 'DeviceIoControl', _            'ptr', $hDrv, _            'dword', 0x70020, _            'ptr', 0, _            'dword', 0, _            'ptr', DllStructGetPtr($DP), _            'dword', 88, _            'dword*', 0, _            'ptr', 0) ;ToolTip($hDrv & " : " & $ret[0]) $NRC = DllStructGetData ($DP, 1, 40) ;NRC:=NumGet(DP,40), $NWC = DllStructGetData ($DP, 1, 44) ;NWC:=NumGet(DP,44), $RC = $NRC - $ORC ;RC:=NRC-ORC, $WC = $NWC - $OWC ;WC:=NWC-OWC, $ORC = $NRC ; $OWC = $NWC ;OWC:=NWC ToolTip($RC & " : " & $WC) If $RC=0 And $WC=0 Then Send ("{NUMLOCK}") ; $IC=_   TraySetIcon("Drive.ico") ElseIf $RC<>0 And $WC=0 Then Send ("{CAPSLOCK}") ; $IC=2   TraySetIcon("Read.ico") ElseIf $RC=0 And $WC<>0 Then Send ("{CAPSLOCK}") ; $IC=3   TraySetIcon("Write.ico") ElseIf $RC<>0 and $WC<>0 Then Send ("{CAPSLOCK}") ; $IC=4   TraySetIcon("Read_Write.ico") EndIf ; Sleep(1000) WEnd





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users