AkelPad Forum Index AkelPad
Support forum
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Scripts discussion (4)
Goto page Previous  1, 2, 3, 4, 5
 
Post new topic   Reply to topic    AkelPad Forum Index -> Plugins
View previous topic :: View next topic  
Author Message
FeyFre



Joined: 07 Aug 2007
Posts: 2237
Location: Vinnitsa, Ukraine

PostPosted: Sun Jun 18, 2017 1:18 pm    Post subject: Reply with quote

Diamen, from JScript? Yes, it is possible to register hotkey. Look for example in history.js script in collection.
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
Diamen



Joined: 15 Aug 2008
Posts: 57

PostPosted: Sun Jun 18, 2017 2:45 pm    Post subject: Reply with quote

I tryed to reuse it but i'm not able.
How to set f.e. a hotkey for ctrl-b ?

Code:
var HOTKEYF_CONTROL = 0x02;
var HOTKEYF_ALT = 0x04;
   
function MAKEWORD(lo,hi)
{
   return (lo & 0xFF) + ((hi & 0xFF)<<8);
}

var _HK_SH = MAKEWORD(0x48,HOTKEYF_ALT|HOTKEYF_CONTROL);
var g_hAkelPad = AkelPad.GetMainWnd();
var WM_USER = 0x0400;
var DT_QWORD = 2;
var DT_WORD = 4;
var AKD_DLLADD = WM_USER + 308;

function test(a){
   alert(a);
}

AddFunction("test",_HK_SH,test,33)

function AddFunction(name,hk,proc,param)
{
   var szof = _X64?8:4;
   var func = AkelPad.MemAlloc(5*szof);
   var mn = AkelPad.MemAlloc((name.length+1)*_TSIZE);
   AkelPad.MemCopy(mn, name, _TSTR);
   AkelPad.MemCopy(func,          mn,      DT_QWORD);    //name
   AkelPad.MemCopy(func+szof,      hk,      DT_WORD);     //hotkey
   AkelPad.MemCopy(func+2*szof,   0,      DT_WORD);     //FALSE
   AkelPad.MemCopy(func+3*szof,   proc,   DT_QWORD);    //proc
   AkelPad.MemCopy(func+4*szof,   param,   DT_QWORD);    //param
    var res = AkelPad.SendMessage(g_hAkelPad, AKD_DLLADD, 0, func);
   AkelPad.MemFree(mn);
   AkelPad.MemFree(func);
   return res;
}

function DelFunction(prs)
{
   AkelPad.SendMessage(g_hAkelPad, AKD_DLLDELETE, 0, prs);
}
Back to top
View user's profile Send private message
FeyFre



Joined: 07 Aug 2007
Posts: 2237
Location: Vinnitsa, Ukraine

PostPosted: Sun Jun 18, 2017 10:24 pm    Post subject: Reply with quote

First of all, you cannot give reference to javascript object(function test) into AKD_DLLADD call. That particular parameter must be raw (low level) code address of stdcall call convention. If you pass object as you did, you'll pass address of data associated with object(i.e. raw internal metadata of javascript interpreter).. and when AP try to call it - you will get access violation. You probably missed it in code:
Code:
HK_CallBackAddr   = oSys.RegisterCallback(HK_CallBack);
func_opentop = AddFunction(rott,_HK_RT,HK_CallBackAddr,CBC_OPENTOP);
func_openall = AddFunction(rota,_HK_RA,HK_CallBackAddr,CBC_OPENALL);
func_showhide = AddFunction(showhide,_HK_SH,HK_CallBackAddr,CBC_SHOWHIDE);
You see, 1st line "converts" javascript function into "native" function address, and only then we register hotkey(in this case we reuse the same function).
Second: script must be resident. Once you registered hotkey, your script must not finish until it unregisters it, or else in best case it will not work, in worst - crash on hotkey activation. The code below is typical pattern of creating resident scripts
Code:
//! INITIALIZATION OF SCRIPT BUSINESS LOGIC: EACH SCRIPT DO IT DIFFERENTLY. WE - PREPARE HOTKEYS
HK_CallBackAddr   = oSys.RegisterCallback(HK_CallBack);
func_opentop = AddFunction(rott,_HK_RT,HK_CallBackAddr,CBC_OPENTOP);
func_openall = AddFunction(rota,_HK_RA,HK_CallBackAddr,CBC_OPENALL);
func_showhide = AddFunction(showhide,_HK_SH,HK_CallBackAddr,CBC_SHOWHIDE);
//! HOOK AKELPAD EVENT QUEUE - THIS GIVES SCRIPT ABILITY REACT ON EVENTS
if(AkelPad.WindowSubClass( WSC_MAINPROC, AkelPadCallBack,
   AKDN_OPENDOCUMENT_FINISH, // THIS IS EVENT RELATED TO BUSINESS LOGIC OF SCRIPT
   AKDN_MAIN_ONFINISH, // THIS EVENT SHOULD BE HOOKED BY ALL RESIDENT SCRIPTS - FIRED WHEN AKELPAD ABOUT TO CLOSE, SO SCRIPT MUST FINISH ITSELF
   AKDN_FRAME_DESTROY // THIS IS EVENT RELATED TO BUSINESS LOGIC OF SCRIPT
))
{
   //! DECLARED OURSELF(SCRIPT) RESIDENT
   AkelPad.ScriptNoMutex();
   //! PROCESS EVENT QUEUE (SCRIPT SITS HERE UNTIL IT IS TIME TO FINISH)
   AkelPad.WindowGetMessage();
   //! UNHOOK EVENT QUEUE - SCRIPTS FINISHES, NOT INTRESTED IN EVENT ANYMORE
   AkelPad.WindowUnsubClass( WSC_MAINPROC );
}
//! CLEANUP EVERYTHING HERE: WE UNREGISTER
DelFunction(func_opentop);
DelFunction(func_openall);
DelFunction(func_showhide);
oSys.UnregisterCallback(HK_CallBackAddr);

In script you see:
HK_CallBack - javascript function which we want to be called on hotkey event
HK_CallBackAddr - PROPER low level function address which (and only it) can be passed to AddFunction.
AkelPadCallBack - handler of AkelPad internal events.. You should rewrite it for your needs. But at least handling of AKDN_MAIN_ONFINISH must be done (to save your time of analysis: call PostQuitMessage(0); must be performed)
When you successfully register script as resident, you will see 'Running' label in script list on it. And if hotkey registered successfully, you will see it in HotKeys plugin in list of "All keys..." (your "test" label will be there).

Why it is so sophisticated? Well, it is one of oldest resident scripts which never was rewritten for new API (+code to handle business logic is not light). I have not followed Scripts plugin development much lately, I suspect there are some easy to use functions introduced, I never rewritten script, because it works as is. Actually this code more or less equal to code on pure C used in plugins (i.e. plugin API used directly). Few magic functions of AkelPad object made it possible to create such complex functionally, which was possible implement only as plugin.
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
yozhic



Joined: 20 Jun 2011
Posts: 214
Location: Электросталь

PostPosted: Sat Nov 11, 2017 12:01 pm    Post subject: Reply with quote

Подскажите, пожалуйста, чайнику: как получить аргументы, переданные скрипту, если скрипт начинается с
Code:
if (typeof AkelPad == "object")

AkelPad.GetArgValue в этом случае не работает (выдает ошибку AkelPad is undefined).
Back to top
View user's profile Send private message
KDJ



Joined: 06 Mar 2010
Posts: 1919
Location: Poland

PostPosted: Sat Nov 11, 2017 1:11 pm    Post subject: Reply with quote

yozhic

Use WScript.Arguments(n) instead of AkelPad.GetArgValue().
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AkelPad Forum Index -> Plugins All times are GMT
Goto page Previous  1, 2, 3, 4, 5
Page 5 of 5

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


SourceForge.net Logo Powered by phpBB © 2001, 2005 phpBB Group