Hello, I have the following code using Red/System that appears to property #import Autohotkey.dll. In using this DLL (whether from Autohotkey or not) it's frequently imperative to insert a delay after the code runs, or the command won't be executed. The simple script in AHK to run Notepad may illustrate this.<br> AhkCom := ComObjCreate("AutoHotkey.Script")
AhkCom.ahktextdll("Run notepad.exe")
While AhkCom.ahkReady()
Sleep, 100
<br>The red-lang code I have so far is this: ```Red/System []
[
"AutoHotkey.dll" cdecl
[
Exec: "ahktextdll" [pointer! [integer!]]
]
]
Exec ["Run notepad.exe"]``` <br>No delay is inserted, because I can't find any documentation on how to insert a delay in Red/System. the Red 'wait' command does not work. All help appreciated. Also greatly appreciated would be any examples of using #import for any non-Windows-OS DLLS, and any real-world examples of using the Visual Basic API as described here at Visual Basic API. Thanks in advance.
sleep (ms)
https://github.com/red/red/blob/master/runtime/platform/win32.reds#L270
f: context [d: 0 return func [n] [d: also d do [d: d + 1 if 1 < n [f n - 1] probe pick ["recursive" "flat"] d > 1]]]
foreach-deep: function ['w b c] [parse b rule: [any [ahead block! into rule | b: skip (set w :b/1 do c)]]]
>> foreach-deep x [a b c [e d f] g] [probe x]
a
b
c
e
d
f
g
== true
@hiiamboris your first example is complex for me:
f: context [
d: 0
return func [n]
[d: d + 1
if 1 < n [f n - 1]
probe pick ["recursive" "flat"] d > 1 d: d - 1
]
]
So, lets go.
f: context [
d: 0
Here you create a context and you initialize it.
return func [n]
I don't understand what you are doing here.
It seems you return a function but I to me RETURN is an istruction which get executed at object creation and I do not know who is RETURN returning the value too !
Also, func [n]
to me need to be assigned to a word...
probe pick ["recursive" "flat"] d > 1 d: d - 1
I have already encountered this kind of expression, but I don't rememeber how it works.
probe pick ["recursive" "flat"] d > 1
d: d - 1
Thanks, that fixed the "sleep" part of my code ... now for the dll call, which apparently did NOT work. @hiiamboris, you know red - I don't. That's why I posted asking for help. You helped, and thanks for that. But it is NOT intuitively clear from ANY of the documentation that
Sleep: "Sleep" [
dwMilliseconds [integer!]
]
also required the #import statement for kernel32.dll.
return
from inside a context block works as if it was inside a function that gets executed, so in effect you get f: bound to the function! valuepick
accepts a logic value as index, true is the 1st one, false is the 2nd