xdevel2000
xdevel2000

Reputation: 21364

Send a key to Windows desktop

I want to build an app to send programmatically keystrokes to Windows desktop and not to a specified windows. For example if we hit arrows keys then the icons in the desktop are selected... Is it possible?

Upvotes: 1

Views: 660

Answers (2)

nanda
nanda

Reputation: 804

SendInput windows API would do what you want. In fact sending input to a targeted window is a more difficult task. SendInput will send the input to the virtual input queue corresponding to the windows session of the process that is calling this API. The input or keys if you will, will land on whatever desktop that is active and inside that whatever window that is in the foreground.

If the Listview control that shows the desktop icons is the foreground window then the arrow keys you would send would move the selection - otherwise it might move a cursor on a notepad (if notepad is the foreground window). Note: Window that is on top is not necessarily the fore ground window. Look at SetForegroundWindow API to know more about the meaning of a fore ground window.

Upvotes: 2

atconway
atconway

Reputation: 21304

You should be able to do this via the LVM_SETITEMPOSITION in the win API. Have a look at the following thread which covers some suggestions already on using this: How can I programmatically manipulate Windows desktop icon locations?

Upvotes: 0

Related Questions