Ticket #31974: patch-src_mac_MacKeyboard.cpp.diff

File patch-src_mac_MacKeyboard.cpp.diff, 3.7 KB (added by marin.saric@…, 13 years ago)
  • src/mac/MacKeyboard.cpp

     
    11/*
    22 The zlib/libpng License
    33 
    4  Copyright (c) 2006 Chris Snyder
     4 Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
    55 
    66 This software is provided 'as-is', without any express or implied warranty. In no event will
    77 the authors be held liable for any damages arising from the use of this software.
    88 
    9  Permission is granted to anyone to use this software for any purpose, including commercial 
     9 Permission is granted to anyone to use this software for any purpose, including commercial
    1010 applications, and to alter it and redistribute it freely, subject to the following
    1111 restrictions:
    1212 
    13  1. The origin of this software must not be misrepresented; you must not claim that 
    14  you wrote the original software. If you use this software in a product, 
    15  an acknowledgment in the product documentation would be appreciated but is 
     13 1. The origin of this software must not be misrepresented; you must not claim that
     14 you wrote the original software. If you use this software in a product,
     15 an acknowledgment in the product documentation would be appreciated but is
    1616 not required.
    1717 
    18  2. Altered source versions must be plainly marked as such, and must not be 
     18 2. Altered source versions must be plainly marked as such, and must not be
    1919 misrepresented as being the original software.
    2020 
    2121 3. This notice may not be removed or altered from any source distribution.
    22 */
     22 */
    2323
     24#ifndef __LP64__
     25
    2426#include "mac/MacKeyboard.h"
    2527#include "mac/MacInputManager.h"
    2628#include "mac/MacHelpers.h"
     
    141143        // if not buffered just return, we update the unbuffered automatically
    142144        if ( !mBuffered || !mListener )
    143145                return;
    144        
    145         //If the mListener returns false, that means that we are probably deleted...
    146         //send no more events and just leave as the this pointer is invalid now...
    147         bool ret = true;
    148        
     146
    149147        // run through our event stack
    150148        eventStack::iterator cur_it;
    151149       
     
    165163//-------------------------------------------------------------------//
    166164std::string& MacKeyboard::getAsString( KeyCode key )
    167165{
    168         getString = "";
    169        
     166    CGKeyCode deviceKeycode;
     167   
     168    // Convert OIS KeyCode back into device keycode
     169    for(VirtualtoOIS_KeyMap::iterator it = keyConversion.begin(); it != keyConversion.end(); ++it)
     170    {
     171        if(it->second == key)
     172            deviceKeycode = it->first;
     173    }
     174   
     175    UniChar unicodeString[1];
     176    UniCharCount actualStringLength = 0;
     177   
     178    CGEventSourceRef sref = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
     179    CGEventRef ref = CGEventCreateKeyboardEvent(sref, deviceKeycode, true);
     180    CGEventKeyboardGetUnicodeString(ref, sizeof(unicodeString) / sizeof(*unicodeString), &actualStringLength, unicodeString);
     181//    NSLog([NSString stringWithFormat:@"%C\n", unicodeString[0]]);
     182    getString = unicodeString[0];
     183
    170184        return getString;
    171185}
    172186
     
    206220                //status = GetEventParameter( theEvent, 'kuni', typeUnicodeText, NULL, 0, &stringsize, NULL);
    207221                //status = GetEventParameter( theEvent, 'kuni', typeUnicodeText, NULL, sizeof(UniChar)*10, NULL, &text );
    208222                status = GetEventParameter( theEvent, 'kuni', typeUnicodeText, NULL, sizeof(UniChar) * 10, &stringsize, &text );
    209                 std::cout << "String length: " << stringsize << std::endl;
     223//              std::cout << "String length: " << stringsize << std::endl;
    210224               
    211225                //wstring unitext;
    212226                //for (int i=0;i<10;i++) unitext += (wchar_t)text[i];
     
    462476        keyConversion.insert(VirtualtoOIS_KeyMap::value_type(0x75, KC_DELETE)); // del under help key?
    463477}
    464478
    465 
    466 
    467 
     479#endif