No BSD License  

Highlights from
keyboard simulation

from keyboard simulation by morteza ahmadi
controlling keyboard

keyboard_simulation(keyboard_string)
function keyboard_simulation(keyboard_string)

% keyboard_string ->      'a'
%                         'hello'


% by : Morteza Ahmadi Najafabadi (matlab7.class@gmail.com)

% I used c code for this function !
% If you already have made desirable 'm_click.mexw32' it is not need to run 'make_m_keyboard'

for i=1:length(keyboard_string)
    keyboard_button=keyboard_string(i);
    make_m_keyboard(keyboard_button)
    m_click

    pause(0.1)
end



function make_m_keyboard(keyboard_button)
%% #1 create m_click.c

tt=['#include "mex.h" //--This one is required '  char([13 10]) ,...
    '#include "windows.h"'  char([13 10]) ,...
    'void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])'  char([13 10]) ,...
    '{'  char([13 10]) ,...
    'keybd_event(VkKeyScan(''' keyboard_button '''),0x9e,0 , 0);'  char([13 10]) ,...
    'keybd_event(VkKeyScan(''' keyboard_button '''),0x9e,KEYEVENTF_KEYUP , 0);'  char([13 10]) ,...
    '}'  char([13 10]) ,...
    ' ']+0;

fid=fopen('m_click1.txt','w+');
fprintf(fid,'%s',tt);
fclose(fid);

dos('del m_click.c');
dos('rename m_click1.txt m_click.c');

%% #2 compile 'm_click.c' and make 'm_click.mexw32'
mex m_click.c





















Contact us at files@mathworks.com