%% Define computer-specific variables
ipA = '150.100.100.20';  portA = 9091;  % Modify these values to be those of your second computer.
ipB = '150.100.100.21';   portB = 9090;   % Modify these values to be those of your first computer.
%% Create UDP Object
udpB = udp(ipA,portA,'LocalPort',portB, 'InputBufferSize', 8);
udpB.Terminator = 'LF/CR';  %tell it about line endings
%% Connect to UDP Object
fopen(udpB)

udpB.Timeout=.1;
h = actxserver('WScript.Shell');
disp 'working...'
run = 'yes';
h.AppActivate('Infiniti Software System');

while strcmp(run, 'yes')
    [~,~,keyCode] = KbCheck;
    if find(keyCode) == 27
        run = 'q';
        disp 'q'
    end
    
    %read from computer 1
    data=fscanf(udpB)
    if ~isempty(data)
        if strcmp(data(1), 'q')
            run=data;
%             break;
        else
           h.AppActivate('Infiniti Software System');
           keyPress = strcat('^',data);
           h.SendKeys(keyPress);
%            data=[];
        end
    end
end

disp 'job done!'
fclose(udpB);


