#6215
Yutaka Emura
Keymaster

zhouzh2 wrote:
Hi,
I just tried to write a macro to do this:

document.selection.CharLeft(true,1);
if (document.selection.Text == "{")
{
document.write ( "{}" );
}
if (document.selection.Text == "[)
{
document.write ( []" );
}
if (document.selection.Text == "(")
{
document.write ( "()" );
}
if (document.selection.Text == "'")
{
document.write ( "''" );
}
if (document.selection.Text == """)
{
document.write ( """" );
}
shell.SendKeys( "{LEFT}" );

I type “(“, run this macro, and get “()”, with the cursor between “(” and “)” .
I assign the “(” key to this macro, but I get nothing when I typed “(“. Is there a way to let Emeditor insert this hotkey before running this macro ? Or how can a macro get the value of the hotkey it’s assigned with?

And anyone got a better idea to do this ?

PS. I also tried to improve this macro. In C, it might be better to insert “{n}” rather than just “{}”, So in short, how to let macros to be more “language specified”?

Thanks!

The following example shows how to find the shortcut for the macro you have just run.


for( nID = 9216; nID <= 9216 + 1023; nID++ ){
str = editor.QueryStringByID( nID );
if( str == ScriptFullName ){
break;
}
}

bFound = false;
list = new Enumerator( document.Config.Keyboard.List );
for( ; !list.atEnd(); list.moveNext() ){
item = list.item();
if( item.Command == nID ){
virtual = item.Flags & eeVirtualKey;
shift = item.Flags & eeShift;
ctrl = item.Flags & eeCtrl;
alt = item.Flags & eeAlt;
str = "The shortcut key = " + item.Key;
if( virtual ){
str += "n Virtual Key";
}
if( shift ){
str += "n with SHIFT";
}
if( ctrl ){
str += "n with CTRL";
}
if( alt ){
str += "n with ALT";
}
alert( str );
bFound = true;
}
}

if( !bFound ) {
alert( "No shortcut found" );
}

Use

document.ConfigName; 

to find the current configuration.