cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar

JSL to input an [Enter] keystroke?

I'm trying to write a script to correctly calculate power for split-unit designs in the Custom Designer and Design Evaluator.  The issue is that the correct degrees of freedom aren't used and while they can now be changed, each time the degrees of freedom or signal to noise ratio is changed the outline boxes for Power Analysis collapse and there's a lot of unnecessary button clicking going on.  Also, I cannot determine how to calculate the Non-Centrality Parameter for split-unit designs so I can't just write a script to do the math from scratch.  In JMP 10 the non-centrality parameter is a hidden column in the Power Analysis which I can get as a matrix.

What I want to be able to do is write a script that a user can run while in Custom Designer or Design Evaluator and have it calculate power for them using several signal to noise ratios all at once.  To do this, my script needs to be able to change the signal to noise ratio in the JMP Platform and have CD or DE recalculate the NCP.

I can change the NumberColEditBox value, but I cannot get the Platform to recalcualte NCP.

win = Window("DOE - Custom Design");  //Connects to the window for testing purposes

win[OutlineBox(15)] << Close(0);  //This is the Power Analysis outline box

win[NumberColBox(9)] << Hide(0);  //This is the NCP column

ncp1 = win[NumberColBox(9)] << Get as Matrix;  //Saves the NCP column

win[NumberColEditBox(4)] << SetValues([4]);  //This changes the Signal to Noise Ratio value in the box to 4

How can I simulate an Enter keystroke to get the platform to recalculate?

I will note that when I change the value in the box from the script and just click in the box and hit Enter, nothing happens.  When I then type in the number I just changed it to and hit Enter, nothing happens.  If I then type in any other number, it works properly.  (that sequence would be like, win[NumberColEditBox(4)] << SetValues([4]); hit enter, nothing -> Type 4 in the box, hit enter, nothing -> Type 3 in the box, hit enter, works)

1 REPLY 1
mattflynn
Level III

Re: JSL to input an [Enter] keystroke?

Some example noodlings with key press function - Windoze   keybd_event function with VK_RETURN

Hope this helps.

Best,

-Matt

// keypress_example.jsl

// Matt Flynn -

// caution when experimenting with keys - can get interesting

//  http://msdn.microsoft.com/en-us/library/ms646301(VS.85).aspx
// http://msdn.microsoft.com/en-us/lib...

// http://msdn.microsoft.com/en-us/library/ms646304(VS.85).aspx
// http://msdn.microsoft.com/en-us/li...

VK_ESCAPE  = Hex to Number( "0000001B" );

VK_H = Hex to Number( "00000048" );

VK_E = Hex to Number( "00000045" );

VK_L = Hex to Number( "0000004C" );

VK_O = Hex to Number( "0000004F" );

VK_F = Hex to Number( "00000046" );

VK_R = Hex to Number( "00000052" );

VK_M = Hex to Number( "0000004D" );

VK_J = Hex to Number( "0000004A" );

VK_M = Hex to Number( "0000004D" );

VK_P = Hex to Number( "00000050" );

VK_SPACE   = Hex to Number( "00000020" );

VK_SHIFT   = Hex to Number( "00000010" );

VK_RETURN  = Hex to Number( "0000000D" );

VK_1 = Hex to Number( "00000031" );

KEYEVENTF_EXTENDEDKEY = Hex to Number( "00000001" ); //&H1

KEYEVENTTF_KEYDOWN = 0;

KEYEVENTF_KEYUP = Hex to Number( "00000002" ); //&H2

kernel32 = Load Dll( "kernel32" );

kernel32 << DeclareFunction( "Sleep", Convention( STDCALL ), Alias( "Sleep" ),

    Arg( Int32, "dwMilliseconds" ),

    Returns( Void ) );                 //If the function succeeds, the return value is nonzero.

user32 = Load Dll( "User32" );

user32 << DeclareFunction( "FindWindowA", Convention( STDCALL ), Alias( "FindWindow2" ),

    Arg( UInt32, input, "lpClassName" ),

    Arg( AnsiString( 200 ), input, "lpCaption" ),

    Returns( UIntPtr )

);  // hWnd

user32 << DeclareFunction( "SetForegroundWindow", Convention( STDCALL ), Alias( "SetForegroundWindow" ),

    Arg( UIntPtr, "hWnd" ),

    Returns( UInt32 )

);

user32 << DeclareFunction( "keybd_event", Convention( STDCALL ), Alias( "keybd_event" ),

        Arg( UInt8, "bVk" ),    //[in] Specifies a virtual-key code. The code must be a value in the range 1 to 254. For a complete list, see Virtual Key Codes.

        Arg( UInt8, "bScan" ),

        Arg( UInt32, "dwFlags" ),

        Arg( UIntPtr, "dwExtraInfo" ),

    Returns( Void ) );

user32 << DeclareFunction( "GetKeyState", Convention( STDCALL ), Alias( "GetKeyState" ),

        Arg( Int32, "nVirtKey" ),    //[in] Specifies a virtual key. If the desired virtual key is a letter or digit (A through Z, a through z, or 0 through 9), nVirtKey must be set to the ASCII value of that character. For other keys, it must be a virtual-key code.

    Returns( Int32 ) ); //The return value specifies the status of the specified virtual key, as follows:

//If the high-order bit is 1, the key is down; otherwise, it is up.

//If the low-order bit is 1, the key is toggled. A key, such as the CAPS LOCK key, is toggled if it is turned on. The key is off and untoggled if the low-order bit is 0. A toggle key's indicator light (if any) on the keyboard will be on when the key is toggled, and off when the key is untoggled.

shell32 = Load Dll( "shell32" );

shell32 << DeclareFunction( "ShellExecuteA", Convention( STDCALL ),    Alias( "ShellExecute" ),

    Arg( UIntPtr, input, "hWnd" ),

    Arg( AnsiString( 20 ), "lpOperation" ),

    Arg( AnsiString( 256 ), "lpFile" ),

    Arg( AnsiString( 256 ), "lpParameters" ),

/*        Arg( UInt32, "lpParameters" ), */

    Arg( UInt32, "lpDirectory" ),

    Arg( UInt32, "nShowCmd" ),

    Returns( UInt32 )

);  //If the function succeeds, it returns a value greater than 32.

Save Text File( "C:\temp\deleteme.txt", "'Hello World' from JMP" );

dirname = "C:\temp";

fname = "C:\temp\deleteme.txt";   

// open in Notepad

rc = shell32 << ShellExecute( 0, "Open", "notepad.exe", " ", 0, 1 );

lpCaption = "Untitled - Notepad";

rc = kernel32 << Sleep( 2 );        // pause to let notepad open

// open in Excel

//rc = shell32 << ShellExecute( 0, "Open", "Excel.exe", " ", 0, 1 );

//lpCaption = "Microsoft Excel - Book1";

// wait for open

rc = kernel32 << Sleep( 200 );        // pause to let notepad open

hWnd = user32 << FindWindow2( 0, lpCaption );

rc = user32 << SetForegroundWindow( hWnd );

key = function( { l_key },

            user32 << keybd_event( l_key, 0, 0, 0 );    // press key

            user32 << keybd_event( l_key, 0, KEYEVENTF_KEYUP, 0 );    // release key

    ); 

user32 << keybd_event( VK_SHIFT, 0, 0, 0 );    // press key

key( VK_H );

user32 << keybd_event( VK_SHIFT, 0, KEYEVENTF_KEYUP, 0 );    // release key

key( VK_E );

key( VK_L );

key( VK_L );

key( VK_O );

key( VK_SPACE );

key( VK_F );

key( VK_R );

key( VK_O );

key( VK_M );

key( VK_SPACE );

user32 << keybd_event( VK_SHIFT, 0, 0, 0 );    // press key

key( VK_J );

key( VK_M );

key( VK_P );

key( VK_1 );

user32 << keybd_event( VK_SHIFT, 0, KEYEVENTF_KEYUP, 0 );    // release key

key( VK_RETURN );

user32 << UnloadDll( );

shell32 << UnloadDll( );

kernel32 << UnloadDll( );