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( );