Hola satael.
Te lo pongo mas facil, esta son las funciones que uso yo habitualmente.
Código Delphi
[-]
function SacaTeclado(): HWND;
var
TecladoPgm: string;
TecladoWND: HWND;
Resultado: integer;
msg: string;
begin
TecladoPGm := 'c:\windows\osk.exe' TecladoWND := FindWindow(nil, 'Teclado en pantalla'); if TecladoWND = 0 then
begin
Resultado := ShellExecute(Application.Handle, 'open', PChar(TecladoPgm), Pchar(''), PChar(ExtractFilePath(TecladoPgm)), SW_SHOW);
case Resultado of
0: msg := 'The operating system is out of memory or resources.';
ERROR_FILE_NOT_FOUND: msg := 'The specified file was not found.';
ERROR_PATH_NOT_FOUND: msg := 'The specified path was not found.';
ERROR_BAD_FORMAT: msg := 'The .exe file is invalid (non-Microsoft Win32 .exe or error in .exe image).';
SE_ERR_ACCESSDENIED: msg := 'The operating system denied access to the specified file.';
SE_ERR_ASSOCINCOMPLETE: msg := 'The file name association is incomplete or invalid.';
SE_ERR_DDEBUSY: msg := 'The Dynamic Data Exchange (DDE) transaction could not be completed because other DDE transactions were being processed.';
SE_ERR_DDEFAIL: msg := 'The DDE transaction failed.';
SE_ERR_DDETIMEOUT: msg := 'The DDE transaction could not be completed because the request timed out.';
SE_ERR_DLLNOTFOUND: msg := 'The specified DLL was not found.';
SE_ERR_NOASSOC: msg := 'There is no application associated with the given file name extension. This error will also be returned if you attempt to print a file that is not printable.';
SE_ERR_OOM: msg := 'There was not enough memory to complete the operation.';
SE_ERR_SHARE: msg := 'A sharing violation occurred.';
else
msg := 'Otro problema';
end;
if Resultado < 32 then
begin
Application.MessageBox(PChar('Problema al ejecutar' + #13 + TecladoPgm + #13 + msg), 'Error', MB_ICONERROR);
Result := TecladoWND;
Exit;
end;
EsperaSegundos(0.5); TecladoWND := FindWindow(nil, 'Teclado en pantalla'); if TecladoWND = 0 then
Application.MessageBox('No encuentro la ventana del teclado', 'Error', MB_ICONERROR);
end;
Result := TecladoWND;
end;
procedure CierraTeclado();
var
TecladoWND: HWND;
begin
TecladoWND := FindWindow(nil, 'Teclado en pantalla'); if TecladoWND = 0 then
Exit;
CloseWindow(TecladoWND); PostMessage(TecladoWND, WM_CLOSE, 0, 0); end;