<commit_before>import string
import win32com.client

class WinappController(object):
    def __init__(self, app=None):
        self.app = app
        self.shell = win32com.client.Dispatch("WScript.Shell")
        
    def send_key(self, key):
        print "App: ", self.app
        if self.app:
            # To set the focus on "app"
            self.shell.AppActivate(self.app)
        self.shell.SendKeys(key)


def get_port():
    port = None
    # First, try RFCOMM using the PyBluez module. This seems to work on Windows 7 (and up) only.
    try:
        import connection_rfcomm
        port = connection_rfcomm.BluetoothRfcomm()
    except:
        # Fallback is "Bluetooth over virtual serial port", as it is more difficult to setup
        # (need for a virtual COM port, and user needs to know that
        # port number). This needs the PySerial module.

        # Ask the user for COM port number. PySerial counts them zero-based, so
        # subtract one (1) from that.
        portnum = int(input("Enter the virtual COM port number for your Bluetooth device: ")) - 1
        import connection_serialport
        port = connection_serialport.BluetoothSerialport(portnum)

    return port

    
# handle special keys
keys = { 'pgdn': '{PGDN}', 
         'pgup': '{PGUP}', 
         'alttab': '%{TAB}', 
         'bkspc': '{BS}', 
         'space': ' ',
         '@': '@',
         'enter': '{ENTER}'}

# handle ordinary ascii/numbers
for k,v in zip(string.lowercase + string.digits, string.lowercase + string.digits):
    keys[k] = v

app = WinappController()
port = get_port()
while True:
    try:
        port.get_connection()
        while True:
            print "Waiting for data on client socket..."
            data = port.get_data()
            print "received [%s]" % data
            if len(data) == 0: break
            if keys.has_key(data):
                print "Sending '%s' to application" % (keys[data],)
                app.send_key(keys[data])
            else:
                print "No key mapping found for '%s'" % (data,)
            
    except IOError:
        pass
    print "disconnected"
    port.close()
port.destroy()
print "all done"
<commit_msg>added Mac OS X support<commit_after>import string
import sys
import app_controller
import bt_connections

app = app_controller.get_app_controller()
port = bt_connections.get_port()
while True:
    try:
        port.get_connection()
        while True:
            print "Waiting for data on client socket..."
            data = port.get_data()
            print "received [%s]" % data
            if len(data) == 0:
                break
            app.send_key(data)
            
    except IOError:
        pass
    print "disconnected"
    port.close()
port.destroy()
print "all done"

{'fraction_non_alphanumeric': 0.10499820208558072, 'fraction_numerical': 0.003236245954692557, 'mean_word_length': 2.084257206208426, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1754380', 'n_tokens_mistral': 826, 'n_tokens_neox': 800, 'n_words': 256}