PDA

View Full Version : keystrokes problem



cafu1007
13th May 2009, 16:02
Hi Everybody,

first at all thanks, this is great place to learn, and share.

my trouble:

I have to access(i do not know wich other way explain) to a running application and send some keystroke like "ctrl+p" or similar, or just keys like Key_Up

i was trying with the windos api function like FindWindow, SendMessage and so on, but i got into conversion errors. and i was trying also with QProcces class but there was not result.

i have looking for a time into the forum before posting redundant question.

i hope i make myself clear.

Thanks in advance

cafu

wysota
14th May 2009, 01:18
If you're targetting Windows only then using SendMessage (or PostMessage) is the best way. Qt won't help you with that - it has no facilities to send keystroke events to other processes. You'll have to go through the native API (and native structures, of course - you can't send Qt events using SendMessage).

cafu1007
14th May 2009, 14:02
Thanks for the answer,

But the problem is i have not been able to use those function i dont know what i am missing,

I have include the window.h file and still not working. ..... help please

cafu

talk2amulya
14th May 2009, 14:12
please share the source code..this is the 73rd time i've said that in this forum

cafu1007
15th May 2009, 09:02
this is how i am trying to find the wiindow and in similar way, ia calling the send message but i really i am not sure about the parameters, and i also was trying SendKeys and it saids that is no defined.( And i am adding windows.h in the header). i really i do not know how to use api windows in qt :crying: :confused::crying::confused:



HWND handel=FindWindow(NULL,"Window Title");



cannot convert `const char*' to `const WCHAR*' for argument `2' to `HWND__* FindWindowW(const WCHAR*, const WCHAR*)'

cafu1007
19th May 2009, 08:58
Hi, I know that is a stupid question but i am really stuck in this point, please help:confused:

wysota
19th May 2009, 13:40
But what is the problem? If you can't get your WinAPI code to work then looking for an answer on a forum dedicated to Qt (where probably more than half of the people there don't use WinAPI) is a much worse solution than looking for the answer on sites dedicated to WinAPI (like MSDN).

The error message suggests you need to cast a regular C string to a wide char string.
Try this: http://www.codeguru.com/forum/showthread.php?t=231165

cafu1007
20th May 2009, 07:48
Ok Sorry for the bother, i thougtht that perhaps was related with QT, and i am not using this cause i want..... i have not fiind another way to control a windows wich i am no creating, is a existeing program and i need to give the order to print and select a configuration on print configuration window.

And Thank all For the answers

tofighi
25th May 2011, 23:18
This is not a perfect solution but working:
http://www.qtcentre.org/threads/41852-How-to-trigger-a-hotkey-or-shortcut-or-emulate-keyboard-with-Qt?p=191905#post191905

dbzhang800
26th May 2011, 03:08
this is how i am trying to find the wiindow and in similar way, ia calling the send message but i really i am not sure about the parameters, and i also was trying SendKeys and it saids that is no defined.( And i am adding windows.h in the header). i really i do not know how to use api windows in qt :crying: :confused::crying::confused:



HWND handel=FindWindow(NULL,"Window Title");



cannot convert `const char*' to `const WCHAR*' for argument `2' to `HWND__* FindWindowW(const WCHAR*, const WCHAR*)'

You'd better write:

HWND handel=FindWindowA(NULL,"Window Title");

or

HWND handel=FindWindowW(NULL, L"Window Title");