예제 #1
0
void
test_AsciiValue_operators()
{
  HandleScope handle_scope;
  Persistent<Context> context = Context::New();
  Context::Scope context_scope(context);

  char TEST_STRING[] = "ascii string value";
  int TEST_LENGTH = strlen(TEST_STRING);
  Handle<String> str = String::New(TEST_STRING);
  do_check_eq(str->Length(), TEST_LENGTH);
  String::AsciiValue asciiString(str);
  const char* one = *asciiString;
  char* two = *asciiString;
  do_check_true(0 == strcmp(TEST_STRING, one));
  do_check_true(0 == strcmp(TEST_STRING, two));
  context.Dispose();
}
예제 #2
0
// ----------------------------------------------------------------------------
void MSW_ProcessMacro::SendMacroString(wxString wsMacro, wxWindow* pWin)
// ----------------------------------------------------------------------------
{
    #ifdef LOGGING
     wxString msg;
     msg.Printf(wxT("ProcessMacro:SendMacroString[%s]"), wsMacro.c_str() );
     //-WriteLog( msg );
     #if defined(LOGGING)
     LOGIT( _T("[%s]"), msg.c_str());
     #endif
    #endif //LOGGING

	char     macroChar;
	string::size_type macroStrIndex = 0 ;
	bool	 bPreviousCapsLockState = false;
	long     attachError = 0;

	// Focus window to accept keystrokes
	// Dont do the following or {ALT} to activate menu won't work
    //-::SetForegroundWindow( (HWND)pWin->GetHandle());
    //-::SetFocus((HWND)pWin->GetHandle());

    // Set focus to SU, else HiddenFrame can get focus after menu scans
    ::SetFocus(g_hWndSketchUp);
    ::SetForegroundWindow(g_hWndSketchUp);

	// Memorize CapsLock position
	if ( m_bCapsLockState == true )
		bPreviousCapsLockState = DoKeyToggle(VK_CAPITAL, OFF);

    // wait for user to stop leaning on the keyboard so we can type in the macro
    DWORD thisThread = GetCurrentThreadId();
    DWORD winThread = GetWindowThreadProcessId( (HWND)(pWin->GetHandle()), NULL);

    //FIXME: attaching fails and is unnecessary when code used in same process
    bool attachOk = AttachThreadInput(thisThread, winThread, true);
    if (not attachOk)
        attachError = GetLastError();
    BYTE lpKeyState[256]={0};
    BOOL getStateOk = GetKeyboardState( lpKeyState);
    //wxString str(wxChar('.'),256);
    //wxString str;
    //msg.Clear();
    if ( attachOk && getStateOk )
    {
        // -------------------------------------------------------------------
        //// -- ways *not* to hold macro while user sleeps on the keyboard ---
        // -------------------------------------------------------------------
        ////for ( int i = 0 ; i < 255; ++i){
        //    //-if ( lpKeyState[i] & 0x01) continue;  // ignore toggle keys
        //    //-if ( lpKeyState[i] & 0x80 ){          // key down
        //    //-if ( lpKeyState[i]  ) str.Append(msg.Format(wxT("[%d][%x]"),i,lpKeyState[i]));   // key down
        ////    if ( (lpKeyState[VK_CONTROL] | lpKeyState[VK_SHIFT] | lpKeyState[VK_MENU]) & 0x80)
        ////    {   //str = str.Format(wxT("Ctrl Status[%d][%x]"),i,lpKeyState[VK_CONTROL]);
        ////        wxMilliSleep(128);
        ////        getStateOk = GetKeyboardState( lpKeyState);
        ////        if (not getStateOk) break;
        ////       i = 0;
        ////    }//else str.Append('.');
        ////}//for
        ////WriteLog(str);

        // If user is leaning on the keyboard, our chars can't get stuffed into the keyboard.
        // wait for user to release Ctrl &/or Shift &/or Alt

        while ((lpKeyState[VK_CONTROL] | lpKeyState[VK_SHIFT] | lpKeyState[VK_MENU]) & 0x80)
        {
            wxMilliSleep(128);
            getStateOk = GetKeyboardState( lpKeyState);
            if (not getStateOk) break;
        }//while
    }//if
   #ifdef LOGGING
    else
    {
        // Attach always fails when we're operating in the same process
        msg.Printf( _T("SendMacroString: failed attach[%d %ld] getState[%d]"),attachOk, attachError, getStateOk);
        //-WriteLog( msg );
        #if defined(LOGGING)
        //LOGIT( _T("[%s]"), msg.c_str());
        #endif
    }
   #endif
    //FIXME: attaching fails and is unnecessary when code in same process
    attachOk = AttachThreadInput(thisThread, winThread, false);
    if (not attachOk)
    {
        attachError = GetLastError();
        #if defined(LOGGING)
        // Attach always fails when we're operating in the same process
        msg.Printf( _T("SendMacroString: failed AttachThreadInput[%d %ld]"),attachOk, attachError);
        //-WriteLog( msg );
        //LOGIT( _T("[%s]"), msg.c_str());
        #endif

    }

    // translate unicode to ascii
    wxWX2MBbuf cb = kmU2C(wsMacro);
    string asciiString(cb);
    string namedMacroString(cb);

	// Process macro characters and named Macro Keys
	while ( macroStrIndex < asciiString.size() )
	{
	    macroChar = asciiString[macroStrIndex++];

		// check for ALT '!',CTRL '^',SHIFT '+',and named macros '{'
		if ( '!' == macroChar ) { m_nShiftFlags |= SEND_ALT_FLAG;  }
		else
		if ( '^' == macroChar ) { m_nShiftFlags |= SEND_CTRL_FLAG; }
		else
		if ( '+' == macroChar ) { m_nShiftFlags |= SEND_SHIFT_FLAG;}
		else
		if ( '{' == macroChar )
        {   // have a named macro eg., {CTRL DN}, {INSERT ON}, {ENTER} etc.
				string::size_type savedMacroStrIndex = macroStrIndex;
				if  ( not FindChar( '}', asciiString, namedMacroString, macroStrIndex) )
				{
					// missing '}' to end named macro, just send single char
					macroStrIndex = savedMacroStrIndex;
					InjectMacroChar('{', 1);
				}//if
				else
				{   // translate named macro to virtual key and inject to kbd queue
					InjectNamedKeyMacro( namedMacroString );
					m_nShiftFlags &= CLEAR_SEND_FLAGS;
				}//else

        }
        else    // inject a single key to keyboard
        {		InjectMacroChar(macroChar, 1);
				//#ifdef LOGGING
                // WriteLog( _T("SendMacroSting[%c]"),wxChar(macroChar) );
				//#endif //LOGGING
				m_nShiftFlags &= CLEAR_SEND_FLAGS;
        }//else

	} // End While


	// restore CapsLock position
	if ( m_bCapsLockState )
		DoKeyToggle(VK_CAPITAL, bPreviousCapsLockState);

}//SendMacro()