|
hi all,
I have a problem with the SendInput() function. Let me paste the code in a button click event here.
//code start
WinExec("notepad",1);
Sleep(1000);
CString str="D:\\sample.gho";
INPUT key[2];
for(int index=0;index<str.getlength();index++)
{
="" ::zeromemory(key,="" sizeof(key));=""
="" key[0].type="key[1].type" =input_keyboard;
="" key[0].ki.wvk="key[1].ki.wVk" =vkkeyscan(str.getat(index));
="" key[1].ki.dwflags="KEYEVENTF_KEYUP;
" key[0].ki.time="key[1].ki.time" =="" 0;
="" key[0].ki.dwextrainfo="key[1].ki.dwExtraInfo=0;
" sendinput(2,key,sizeof(input));
="" }
="" code="" end
this="" is="" supposed="" to="" invoke="" the="" notepad="" window="" and="" then="" write="" "d:\\sample.gho"="" in="" it.
but="" it="" writing="" "d;\\sample.gho"=""
can="" anybody="" help="" me?
thanks="" advance.
=""
<div="" class="ForumSig">SYAMLAL
|
|
|
|
|
SyamlalS wrote: This code is supposed to invoke the notepad window and then write "D:\\sample.gho" in it.
But it is writing "d;\\sample.gho"
what the difference are you worrying abt capital D and ; or some other problem
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
ThatsAlok wrote: what the difference are you worrying abt capital D and ; or some other problem
yes, of course I am worried about the case of 'D' and semi colon
pls give solution
Thanks
SYAMLAL
|
|
|
|
|
To type 'D' and ':' you would have to press the Shift key, I suspect that you need to do the same for SendInput.
|
|
|
|
|
Pls explain how can I send the shift key through sendInput()
SYAMLAL
|
|
|
|
|
SyamlalS wrote: //code start
WinExec("notepad",1);
To start with, I wonder , why you are using this API, if there are better options available.
SyamlalS wrote: But it is writing "d;\\sample.gho"
You have not considered virtual key state, which can be VK_SHIFT or VK_CAPITAL in this case.
Your code should be modified like this,
WinExec("notepad",1);
Sleep(1000);
CString str(_T("d:\\sample.gho"));
INPUT key[2];
int nLeng = str.GetLength();
for(int index=0;index < nLeng;index++ ){
::ZeroMemory(key, sizeof(key));
key[0].type = key[1].type = INPUT_KEYBOARD;
SHORT nKeyCode = VkKeyScan(str[index]);
if (VK_SHIFT & nKeyCode)
{
key[0].ki.wVk = VK_SHIFT;
key[0].ki.dwFlags = KEYEVENTF_KEYUP;
key[1].ki.wScan = str[index];
key[1].ki.dwFlags = KEYEVENTF_UNICODE ;
}
else if (VK_CAPITAL & nKeyCode)
{
key[0].ki.wVk = VK_CAPITAL;
key[0].ki.dwFlags = KEYEVENTF_KEYUP;
key[1].ki.wScan = str[index];
key[1].ki.dwFlags = KEYEVENTF_UNICODE ;
}
else
{
key[1].ki.wVk = nKeyCode;
key[1].ki.dwFlags = KEYEVENTF_UNICODE ;
}
key[0].ki.time = key[1].ki.time = 0;
key[0].ki.dwExtraInfo = key[1].ki.dwExtraInfo=0;
SendInput(2,key,sizeof(INPUT));
}
|
|
|
|
|
hi,
I tried with the code which u gave. But I am getting an error message when I go for a build
'KEYEVENTF_UNICODE' : undeclared identifier
Pls help
SYAMLAL
|
|
|
|
|
Ohh ! you need to use latest platform SDK for that.
And , if you are using VC6, then you need to direct, include directories path to latest platform SDK.
Refer this FAQ[^] for more info.
|
|
|
|
|
What happened ? Do you able to resolve this ?
|
|
|
|
|
Installation of SDK is not over,,Once done I will get back to you
Thanks for everything
SYAMLAL
|
|
|
|
|
hi
I selected the SDK for Microsoft Server 2003,and installed it.
What should I do next to get the code compiled.
Please do reply.
SYAMLAL
|
|
|
|
|
Shyamal,
What about this problem ? Does it get solved ?
|
|
|
|
|
Nop Prasad,that is not yet done.
I have kept it aside, since it is not immediately required
Neway, Warm welcome for ur helps regarding the same...
Thanks,
SYAMLAL
|
|
|
|
|
|
How could I judge it, it assume that I have a path like C:\My folder\Myfile\, how to judge if this folder can be written? Note, path may be on a read-only CD or from network with no write privilege, is there a API to complete this function?
I tried CreateFile, while it fail with the error code ERROR_ACCESS_DENIED it is have no write privilege, what I want to know is that if there are other methods to do so?
3ks and best regards.
One day a pretty girl asked me:"Do u think you are handsome?" "I don't think so!".She gave a slap in my face:"Why lying?"...
|
|
|
|
|
How about the GetFileAttributes()[^] API?
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
GetFileAttributes?? I don't think it can work properly. Here I have a path, GetFileAttributes can only get its attribute, how could i know if i can write in the folder. Even the folder is read-only, I can create file in it, right?
One day a pretty girl asked me:"Do u think you are handsome?" "I don't think so!".She gave a slap in my face:"Why lying?"...
|
|
|
|
|
Oh yeah, sorry
It seems like checking all the possibilities (security, writable device, etc) would be alot
more work than just checking the return from CreateFile().
Maybe there's an easier API - I don't know what it is.
Mark
"Great job, team. Head back to base for debriefing and cocktails."
(Spottswoode "Team America")
|
|
|
|
|
HI,
I would like to send a scroll message to Other app(like explorer.exe, IE, notepad.exe....) Using Code like this:::SendMessage(hwnd,WM_VSCROLL,SB_LINEDOWN,0);
It succeed in these APP, but when i try to send the message to MS WORD and OPERA, it failed.
Is this a MDI's reason, How can i solve this?
thanks.
|
|
|
|
|
worker thread did not survive the release version - MFC
in the debug version it did not clash and ran smooth, and completed the cyclesequence function
but it clashed badly in the release version. cyclesequence function was never completed
sry i am very bad in threading. i have search all over but cannot find the solution
ok here's how my program goes
when the user presses a button called "RUN" , i begin my thread
void COpc_serialDlg::OnRun() <br />
{ <br />
m_th_sequence = AfxBeginThread(th_start_sequence, (LPVOID)this );<br />
m_run.EnableWindow(FALSE);<br />
<br />
}<br />
my thread begins by obtaining information from editboxes and starts a function called CycleSequence
<br />
UINT COpc_serialDlg::th_start_sequence(LPVOID lpvParam)<br />
{<br />
COpc_serialDlg *th_start_receiving = (COpc_serialDlg*)lpvParam;
int times = 0;<br />
CString startstring = "";<br />
CString repeatstring = "";<br />
CString endstring = "";<br />
times = th_start_receiving->GetDlgItemInt(IDC_REPEAT_TIMES1);<br />
th_start_receiving->GetDlgItemText(IDC_STARTKEY1 , *startstring);<br />
th_start_receiving->GetDlgItemText(IDC_REPEAT1 , *repeatstring);<br />
th_start_receiving->GetDlgItemText(IDC_ENDKEY1 , *endstring);<br />
th_start_receiving->CycleSequence(times, *startstring, *repeatstring, *endstring);<br />
th_start_receiving->PrintRedDebugMsg( "Cycle thread exiting");<br />
th_start_receiving->m_run.EnableWindow(TRUE);<br />
<br />
return 0;<br />
}<br />
here's how CycleSequence function looks like
int COpc_serialDlg::CycleSequence(int times, CString startstring, CString repeatstring, CString endstring)<br />
{<br />
<br />
CString temp_string = "";<br />
int i = 0;<br />
int Stroke_Count = GetNumberOfStrokes( startstring);<br />
CString local_repeatstring = "";<br />
CString local_repeatstring2 = "";<br />
<br />
<br />
<br />
for( i = 0 ; i < Stroke_Count ; i++)<br />
{<br />
<br />
local_repeatstring = startstring;<br />
<br />
<br />
m_serial.Write(Read_Out_Int(local_repeatstring),1,0,0,10);
startstring = Remove_Out_Int(startstring);<br />
<br />
SetTimer( 999 , 15000 , NULL);<br />
WaitForSingleObject(m_idle_event , INFINITE);
<br />
}<br />
<br />
Stroke_Count = GetNumberOfStrokes( repeatstring);<br />
for( i = 0 ; i < times ; i++)<br />
{<br />
local_repeatstring = repeatstring;<br />
for( int j = 0 ; j < Stroke_Count ; j++)<br />
{<br />
local_repeatstring2 = local_repeatstring;<br />
ResetEvent(m_idle_event);
<br />
<br />
PrintRedDebugMsg( "Waiting done");<br />
m_serial.Write(Read_Out_Int(local_repeatstring2),1,0,0,10);
local_repeatstring = Remove_Out_Int(local_repeatstring);<br />
<br />
SetTimer( 999 , 15000 , NULL);<br />
WaitForSingleObject(m_idle_event , INFINITE);
<br />
}<br />
}<br />
<br />
Stroke_Count = GetNumberOfStrokes( endstring);<br />
<br />
<br />
<br />
for( i = 0 ; i < Stroke_Count ; i++)<br />
{<br />
<br />
local_repeatstring = endstring;<br />
<br />
<br />
m_serial.Write(Read_Out_Int(local_repeatstring),1,0,0,10);
startstring = Remove_Out_Int(startstring);<br />
<br />
SetTimer( 999 , 15000 , NULL);<br />
WaitForSingleObject(m_idle_event , INFINITE);
<br />
}<br />
PrintRedDebugMsg( "End of cycle reached");<br />
return 0;<br />
}
there are also other functions in CycleSequence like m_serial.Write , Remove_Out_Int and Read_Out_Int and GetNumberOfStrokes
i did not include them here because i dont think they are causing the problem.
i believe the problem is the way i initalize stuff in cyclesequence and the way i do my loops
using:
- winxp
- VC++ 6.0
- MFC
|
|
|
|
|
Function UINT COpc_serialDlg::th_start_sequence(LPVOID lpvParam) must be static
|
|
|
|
|
awah wrote: there are also other functions in CycleSequence like m_serial.Write , Remove_Out_Int and Read_Out_Int and GetNumberOfStrokes
i did not include them here because i dont think they are causing the problem.
Not necessary. Its very difficult from seeing this code, to find out the problem.
You can put down message boxes in code and narrow down the rpblem code.
Additionally , refer this article by Joseph M. NewComer Joseph M. NewComer[^].
|
|
|
|
|
awah wrote: my thread begins by obtaining information from editboxes
Well, this is a definite no-no from worker threads.
Never touch the GUI from a worker thread, it may cause a deadlock.
Read Joe Newcomer's article on the subject to get a better understanding of how to do worker threads here[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote "High speed never compensates for wrong direction!" - unknown
|
|
|
|
|
Just opened the readme to VseDebug it says it works with
Visual studio.net 2002 2003 Anyone know if you can build it With Visual Express 2005
|
|
|
|
|
The following code on a linux gcc compiler gave me an error message:
error - SO C++ forbids declaration of "vector" with no type
apparently,
vector <double> dd; is okay because double is a known type
How can I make g++ recognize t_vertice as a valid type?
Or how can I switch off the ISO compatibilty on the g++ compiler?
_________________________________________________
#ifndef HSI3D_H
#define HSI3D_H
#include <qgl.h>
#include <vector>
#include <iostream>
#include "../imageplus.h"
#include <qimage.h>
class HSI3D : public QGLWidget
{
Q_OBJECT
public:
HSI3D(QWidget *parent=0, const char *name=0);
HSI3D(const ImagePlus &Image, QWidget *parent=0, const char *name=0);
~HSI3D();
typedef struct t_vertice{
uchar red;
uchar green;
uchar blue;
float h;
uchar s;
uchar i;
}t_vertice, *ptrtvertice;
vector <t_vertice> puntos;
int quants_punts;
-- modified at 0:02 Thursday 1st March, 2007
|
|
|
|
|