Enter simulieren



  • Hallo

    Ich hab ein kleines Problem mit dem Programm. Das Programm soll einen Text an eine andere Anwendung schicken und dort absenden. Die Nachricht senden klappt einwandfrei und kommt auch dort an wo sie soll. Das Problem ist jenes, das sich der Enterdruck nicht ausführen läßt bzw keine Wirkung hat.
    Das ganze passiert in einen JavaApplet von einem Browser (Zielanwendung). Hier mal der Sourcecode: (Sorry für den schlechten QC, fang erst an mit der API 🙂 )

    #include <windows.h>
    #include <cstdlib>
    #include "resource.h"
    using namespace std;
    
    extern int __argc;
    extern char **__argv;
    
    char szCaption[80];
    char szTime[10];
    UINT_PTR uTimer = 1;
    
    HWND hWndMainWin;
    HWND hWndSec;
    HWND hWndEdit;
    
    INT_PTR CALLBACK DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
    {
    	DialogBox(hInstance, MAKEINTRESOURCE(IDD_BOT), NULL, DlgProc);
    }
    
    INT_PTR CALLBACK DlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	switch(msg)
    	{
    		case WM_INITDIALOG:
    		{
    			return TRUE;
    		}
    
    		case WM_COMMAND:
    		{
    			switch(LOWORD(wParam))
    			{
    				case IDC_GO:
    				{
    					if(!GetDlgItemText(hWnd, IDC_WINCAPTION, szCaption, 80))
    					{
    						MessageBox(hWnd,"ENTER THE WINDOW CAPTION","BotError",MB_OK|MB_ICONERROR);
    					}
    					else
    					{
    						if(!GetDlgItemText(hWnd,IDC_TIME,szTime,10))
    						{
    							MessageBox(hWnd,"ENTER A POSITIVE INTEGER VALUE","BotError",MB_OK|MB_ICONERROR);
    						}
    						else
    						{
    							hWndMainWin = FindWindow(NULL,szCaption);
    							hWndSec = FindWindowEx(hWndMainWin, NULL, "SunAwtCanvas", NULL);
    							hWndEdit = FindWindowEx(hWndSec, NULL, "Edit", NULL);
    							if((hWndMainWin == NULL)||(hWndSec == NULL)||(hWndEdit == NULL))
    							{
    								MessageBox(hWnd,"HANDLE NOT FOUND","BotError",MB_OK|MB_ICONERROR);
    							}
    							else
    							{
    								int i = atoi(szTime);
    								i = i * 1000;
    								SetTimer(hWnd,uTimer,i,NULL);
    							}
    						}
    					}
    					return TRUE;
    				}
    
    				case IDC_STOP:
    				{
    					KillTimer(hWnd, uTimer);
    					return TRUE;
    				}
    
    				case IDC_EXIT:
    				{
    					KillTimer(hWnd, uTimer);
    					EndDialog(hWnd,wParam);
    					return TRUE;
    				}
    			}
    		}
    		return TRUE;
    
    		case WM_TIMER:
    		{
    			//??? TEXTDATEI NUTZEN ???
    			char text[] = "Test message.";
    
    			SetFocus(hWndEdit);
    			SendMessage(hWndEdit,WM_SETTEXT,0,(LPARAM)text);
    			//Enter sim.
    			SendMessage(hWndEdit,WM_SETTEXT,0,(LPARAM)0x13);
    
    			//SendMessage(hWndEdit,WM_KEYUP,VK_RETURN,1);
    
    			//keybd_event(VK_RETURN,0,0,0);
    			//keybd_event(VK_RETURN,0,KEYEVENTF_KEYUP,0);
    
    			return 0;
    		}
    	}
    	return FALSE;
    }
    

    Bei WM_TIMER liegt das Problem nach Enter sim.

    PS: Ich hab schon fast alles ausprobiert was im Forum zu finden war, doch nichts funktioniert so recht 😞



  • such hier mal nach keybd_event...



  • sorry, aber guck mal bei WM_TIMER in meinem source nach, ich habs schon damit versucht. klappt nicht so ganz.



  • Hab deinen Beitrag jetzt nicht ganz durchgelesen, aber versuch s mal mit SendInput.

    Greets
    M.T.



  • Hmm, das hab ich auch schon gefunden, nur komm ich nicht so recht klar mit der Funktion :(. Hat dafür jemand vlt mal ein kleines Bsp? Das wäre wirklich nett.
    Ansonsten schau ich es mir jetzt nochmal an.

    EDIT:

    Hab jetzt folgendes Ausprobiert:

    void pressKey(int vKey) 
    { 
        KEYBDINPUT ki={0}; 
        ki.wVk = vKey; 
        ki.wScan = MapVirtualKeyEx(vKey, 0, GetKeyboardLayout(0)); 
        ki.time = 10; 
    
        INPUT ipEvent; 
        ipEvent.type = INPUT_KEYBOARD; 
        ipEvent.ki = ki; 
    
        SendInput(1,&ipEvent,sizeof(INPUT)); 
    }
    

    Aber beim compilieren hagelt es fehler ohne ende das er KEYBDINPUT, INPUT und SendInput nicht kennen würde..., hab doch aber die windows.h eingebunden.

    g:\Entwicklung\VisualC++\Bot\main.cpp(119) : error C2065: 'KEYBDINPUT' : undeclared identifier
    g:\Entwicklung\VisualC++\Bot\main.cpp(119) : error C2146: syntax error : missing ';' before identifier 'ki'
    g:\Entwicklung\VisualC++\Bot\main.cpp(119) : error C2065: 'ki' : undeclared identifier
    g:\Entwicklung\VisualC++\Bot\main.cpp(119) : error C2059: syntax error : '{'
    g:\Entwicklung\VisualC++\Bot\main.cpp(119) : error C2143: syntax error : missing ';' before '{'
    g:\Entwicklung\VisualC++\Bot\main.cpp(119) : error C2143: syntax error : missing ';' before '}'
    g:\Entwicklung\VisualC++\Bot\main.cpp(120) : error C2228: left of '.wVk' must have class/struct/union type
            type is ''unknown-type''
    g:\Entwicklung\VisualC++\Bot\main.cpp(120) : error C3861: 'ki': identifier not found, even with argument-dependent lookup
    g:\Entwicklung\VisualC++\Bot\main.cpp(121) : error C2228: left of '.wScan' must have class/struct/union type
            type is ''unknown-type''
    g:\Entwicklung\VisualC++\Bot\main.cpp(121) : error C3861: 'ki': identifier not found, even with argument-dependent lookup
    g:\Entwicklung\VisualC++\Bot\main.cpp(122) : error C2228: left of '.time' must have class/struct/union type
            type is ''unknown-type''
    g:\Entwicklung\VisualC++\Bot\main.cpp(122) : error C3861: 'ki': identifier not found, even with argument-dependent lookup
    g:\Entwicklung\VisualC++\Bot\main.cpp(124) : error C2065: 'INPUT' : undeclared identifier
    g:\Entwicklung\VisualC++\Bot\main.cpp(124) : error C2146: syntax error : missing ';' before identifier 'ipEvent'
    g:\Entwicklung\VisualC++\Bot\main.cpp(124) : error C2065: 'ipEvent' : undeclared identifier
    g:\Entwicklung\VisualC++\Bot\main.cpp(125) : error C2228: left of '.type' must have class/struct/union type
            type is ''unknown-type''
    g:\Entwicklung\VisualC++\Bot\main.cpp(125) : error C2065: 'INPUT_KEYBOARD' : undeclared identifier
    g:\Entwicklung\VisualC++\Bot\main.cpp(125) : error C3861: 'ipEvent': identifier not found, even with argument-dependent lookup
    g:\Entwicklung\VisualC++\Bot\main.cpp(126) : error C2228: left of '.ki' must have class/struct/union type
            type is ''unknown-type''
    g:\Entwicklung\VisualC++\Bot\main.cpp(126) : error C3861: 'ipEvent': identifier not found, even with argument-dependent lookup
    g:\Entwicklung\VisualC++\Bot\main.cpp(126) : error C3861: 'ki': identifier not found, even with argument-dependent lookup
    g:\Entwicklung\VisualC++\Bot\main.cpp(128) : error C2070: ''unknown-type'': illegal sizeof operand
    g:\Entwicklung\VisualC++\Bot\main.cpp(128) : error C3861: 'SendInput': identifier not found, even with argument-dependent lookup
    g:\Entwicklung\VisualC++\Bot\main.cpp(128) : error C3861: 'ipEvent': identifier not found, even with argument-dependent lookup
    g:\Entwicklung\VisualC++\Bot\main.cpp(128) : error C3861: 'INPUT': identifier not found, even with argument-dependent lookup
    

    Bitte Helfen! THX



  • Möglicherweise musst du erst noch definieren, das Win98 dein Minimal-System (laut MSDN/PSDK läuft SendInput() ab win98):
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winprog/winprog/using_the_windows_headers.asp

    ...oder deine Windows-Header sind einfach nicht neu genug. In dem Falle dürfte das installieren des Platform SDKs helfen.



  • Hmm, ich hab VC++ .NET 2003, dürfte ja wohl neu genug sein, oder? 😃
    Ich schau mir den Link mal an, vlt klappts ja.

    THX

    EDIT:

    Ok, comp. hat geklappt, aber jetzt sind neue Errors da. hab mich an den Link gehalten und die Macros für WinXP genommen und nun das... 😞

    g:\Entwicklung\VisualC++\Bot\main.cpp(1) : error C2008: '>' : unexpected in macro definition
    g:\Entwicklung\VisualC++\Bot\main.cpp(2) : error C2008: '>' : unexpected in macro definition
    c:\Programme\Microsoft Visual Studio .NET 2003\Vc7\PlatformSDK\Include\Windows.h(24) : fatal error C1017: invalid integer constant expression
    


  • Bei #define das ">=" noch mit drin ?!

    // Mindest-System: WinXP
    #define _WIN32_WINDOWS 0x0501
    #define WINVER 0x0501
    
    #include <windows.h>
    


  • ja, hatte das ">=" noch mit drinn, *ups* habs jetzt entfernt und läßt sich super compilieren.

    THX


Anmelden zum Antworten