Process Windows & SendInput (2 questions)

T

Ted

I'm new to the group, and new to C#. I'm learning it for my job where
I am building for C# without Visual Studio.

As a result, much of the stuff I've learned thusfar I've had to find
from google. I'm doing ok, and I am gaining reliability in my
programs, but I'm still having a great deal of trouble with 2 specific
things. Please note, much of this is for "macros" for work, and my
office is only comfortable with C# programs.

First, I'm using Process.Start() to open up web-pages which works
great, but I can't figure out how to get from the Process variable to
the Window to the Controls so that I can actually access specific
parts of the web document. Guidance there is much appreciated.

Second, and more importantly. Even if I can never access specific
Process/Window controls, I can still build a work around by simply
clicking on them with the mouse. Moving the mouse around the screen
is nothing (Cursor.Position) but I'm having a lot of trouble
understanding SendInput() and how to actually use the complex API to
send a basic mouse click.

Thank you ahead of time for any help you can give.
 
T

Ted

Why aren't you using Visual Studio?

The Express version of Visual Studio is free:http://www.microsoft.com/express/Downloads/

I'm not permitted to download or install programs at my workplace, so
VS, or any other program is out.

I managed to, on my own, access and control Microsoft Office through
the interop assemblies. The SendKeys class has worked quite well for
all of my purposes in programming keyboard input, but I still need to
control the mouse in order to automate web interaction.

Does anyone know how to send mouse clicks? That was my initial
question. I can move the cursor as I need, I just need to send a
click.

My second question was controling web documents. I know about direct
requesting information from web-pages, but because I'm on a secure
server with proprietary code, that is out. I have to do this manually
using the webpage gui, but it would be much easier to move around a
web-page if I could gather from the browser basic information about
the page (like the location of dom objects). In other words, if
there's a link 350px from the top and 170px from the left, then I can
move there to click it. I know this information is readily available
because google chrome spits it out as part of its debug. All I need
is the ability to access it so that I can move about the webpage
freely.

Thanks again for any help you can give.
 
T

Ted

Given that the experts in this newsgroup are experts in C# and .NET, and
your question has basically nothing to do with either, I think you did
well to get the answers you did.

Huh? C# is a .NET programming language. I'm curious how to use that
programming language to emulate a mouse click.

How is that not a C# question? How is that not a .NET question? I'm
so confused!
 
T

Ted

C# has no features for interacting with Windows at all.  So that's
already one strike in terms of being on-topic.

We often get .NET-related questions here as well, which are strictly
speaking not on-topic, but have been de facto "adopted" as relevant
here, because of the strong ties between C# and .NET.

But since .NET doesn't provide a SendInput() method anywhere, your
question can't possibly be relevant to .NET either.  Your question was
frustratingly vague, but it does appear to have enough information to
inform us that it's not actually related to C# or .NET.


Hopefully the above clears things up.

If and when you figure out what you actually want to do in unmanaged
code, and you have specific C#-related questions regarding how to access
unmanaged features from C# (e.g. through p/invoke), then that would be
on-topic.

Pete

I have to be honest, I have no clue what p/invoke is/means. I've read
it several times, but it doesn't make any sense to me. This I do
know. when searching for c# functions I came across this.
http://msdn.microsoft.com/en-us/library/ms646310(VS.85).aspx

This is from the msdn library regarding functions that can send
commands.

If by not interacting with windows you mean it requires references to
dlls etc, then you really couldn't talk about much, if anything here
given that almost anything requires a reference to at least System.dll

What exactly am I asking wrong? I know that C# (or some reference/
invoke) has control.Click and SendKeys. Both of these functions are
great. I can position the mouse with cursor.position, but I cannot
figure out how to activate a mouseclick action. I'm not trying to be
rude, I just don't know the answer to this question. Believe me when
I say I've researched it. Heck, I'm writing a tutorial C# at the
moment since there are none out there for people who do not have
access to visual studio.
 
T

Ted

That is an erroneous interpretation of what I wrote.

The p/invoke (aka "interop", aka "platform invoke") features of .NET are
specifically for interoperability with _unmanaged_ code.  And as I said,
it's not discussions of the p/invoke feature itself that are off-topic;
it's discussions of the _unmanaged_ API that are.

For example: let's suppose there's an unmanaged function named
FindWindow() in the Win32 API you want to use.  If you want to know how
that function works, that's off-topic here.  If you already know how the
function works but want to know how to call it from C#, that's on-topic.

Which is not to say the unmanaged API doesn't get discussed here now and
then.  Just that snide comments about "stumping the experts" when you're
asking off-topic questions such as those dealing with the unmanaged API
specifically are unwarranted and foolish.


Neither of those were mentioned in your original post.  The
Control.Click event won't help you to interoperate with other processes
(.NET or otherwise).  The SendKeys class can help a little, but you
specifically asked about sending mouse input, which SendKeys can't do
(hence the name, Send>>KEYS<<).


Great how?  Control.Click isn't even a function (it's an event) and
SendKeys doesn't do any mouse input.  In what way do they pertain to
your question?

The fact remains that .NET offers very little in terms of direct support
of inter-process user-input simulation.  There are lots of features in
Windows for that sort of thing, particularly the Windows Automation and
Accessibility APIs.  But you need to know how to use those in
_unmanaged_ code first before you start thinking about using them in C#.
  And asking how to use those APIs in unmanaged code is off-topic here,
and unlikely to get much in the way of useful replies.  If you want
those kinds of questions answered, you need to find a newsgroup where
they are on-topic.

Pete

cool. So what's unmanaged code?
 
A

Arne Vajhøj

.NET is managed code. Unmanaged code is everything else.

I would tend to consider Java, Python etc. managed as well - just
managed by another runtime than .NET.

Arne
 
T

Ted

True enough.  I would call those managed environments as well.

But in the context of .NET, as .NET doesn't manage code written in Java,
Python, etc., it's unmanaged as far as .NET is concerned.  And after
all, .NET is the context here.

Pete

so in .NET what are the code limitations?
 
T

Ted

What do you mean by "code limitations"?

limitations on what I can ask questions about I guess. What are the
things .NET can't do with "managed" code would be the phrase I guess--
not that I understand p/invoke any better after the explanations I've
been given.
 
T

Ted

You can and may ask _any_ question you like.  You will not necessarily
be able to know a priori whether what you want to do is supported
directly by .NET.

But when you're told that the desired functionality is not support
directly by .NET, you should not even need to be told explicitly that
your next step should be to look to a different group of people for your
answer than those who are specifically looking at C#- and .NET-related
questions.

Pete

http://groups.google.com/group/micr...a61b930d?lnk=gst&q=sendinput#153db60ea61b930d

so, in the subject of on-topic for this group. How does this work?
 
T

Ted

Sorry, I'm afraid I don't understand your reference to that thread.
What, _specifically_, are you asking about?  How does _what_ work?

If you're asking about the SendInput() function, you can find
documentation for that here:http://msdn.microsoft.com/en-us/library/ms646310(VS.85).aspx

For in-depth details on how to use that function, you should seek help
in a Win32 programming forum.  It's not supported directly in .NET.

If you're asking about the p/invoke support in .NET, you can find
documentation for that here:http://msdn.microsoft.com/en-us/library/ms172270.aspx

That's the top-level documentation page…drill down to the specific
topics within for the details.

If you have a specific, on-topic question, please do ask it.  Vague,
generalized questions are best answered by reading the documentation.
Answering such questions here would effectively just duplicate here
what's already in the documentation.

Pete

How do I p/invoke the function I linked to. That was the exact
question presented there and I didn't understand the answer, which of
course is why I asked this question int he first place.
 
T

Ted

I still don't understand the question.  "p/invoke" is the name of the
.NET feature.  You "p/invoke" something simply by providing the
appropriate declaration and then calling the method declared by that
declaration.  Once the declaration has been done correctly, you just
call it.

There's a web site,http://www.pinvoke.net/, that is basically a wiki
where people publish p/invoke declarations for a variety of Win32 APIs.
  If you want to know what declaration to use for a specific Win32
function, that would be a good place to start.

Pete

I've read through that site quite extensively. Not only are there
disagreements as to how to p/invoke this function, but the site is
also extremely hard to read.

That said, being able to properly p/invoke seems like it would be
pretty core to c#. So with this particular function, how would i
properly p/invoke it so that it is actually usable?

Thanks again for all your help.
 
T

Ted

I disagree.  The site is very simple: you find the API you want, and
then look at the code provided.  If you can't read code, you should
learn to do that first, before you try writing it yourself.

As far as the "disagreements" go, in practically every case it's not an
actual disagreement; it's just that depending on one's actual needs,
there are multiple ways to do the same thing.

For example, given the following actual C declaration:

   void foo(char * pch);

I could in fact call that function using a prototype like this:

   void foo(void * pch);

(Assuming non-decorated names, or otherwise mapping to the actual
function entry point, of course).

Likewise, more than one p/invoke declaration can accomplish the same
basic goal of calling a given unmanaged function.


It's not "core" at all.  The vast majority of C# programs are written
without using p/invoke at all.


The pinvoke.net web site has the details you need.  If you have tried to
use that information that already exists there and are having some kind
of problem, please feel free to ask a _specific_ question about it,
explaining what you've tried, what happens, and why that's different
from what you expected/hoped for.

Pete

My _specific_ question was asked about six times and told it was not
relevant. I asked "how do I simulate a mouse click". Cursor.Position
allowed me to move the mouse, and SendKeys allowed me control over the
keyboard, since my primary task is "macros" I needed to simulate mouse
clicks in order to have full control. I have, since, figured out how,
and for anyone who'd like to know, I can present a basic program. I
have no desire to be talked down to by people who obviously don't even
know the meaning of the word "specific" so don't expect any further
questions from me. I'll help anyone who needs it since clearly you
are incapable of doing so
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top