Hi,
I'm trying to send key stroke to winamp Jump to File window, using c#, when is not in foreground but I don't know how.
So far I managed to send keys to winamp like "c" key to toggle play/pause using this example (this example work even when winamp is minimized):
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
class Test
{
[DllImport("User32.Dll", EntryPoint = "PostMessageA")]
static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow([MarshalAs(UnmanagedType.LPTStr)] string lpClassName,
[MarshalAs(UnmanagedType.LPTStr)] string lpWindowName);
public static void com()
{
IntPtr hwnd = FindWindow("Winamp v1.x", null);
PostMessage(hwnd, 0x100, 0x43, 0);
}
}
}
0x43 is the Virtual-Key Code for „C" key.
Can someone help me with this problem and give me an example of haw I can send keys to Jump to File window in winamp?
VulpesPosted Feb 12, 2012, 2:48 PM
CatalinPosted Feb 13, 2012, 2:48 PM
Hello again.
Using your advice I managed to send keys to "Jump to File" window.
Below is the script that works perfect for me:
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
class test
{
[DllImport("User32.Dll", EntryPoint = "PostMessageA")]
static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow([MarshalAs(UnmanagedType.LPTStr)] string lpClassName,
[MarshalAs(UnmanagedType.LPTStr)] string lpWindowName);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
public static void comm()
{
IntPtr hwnd = FindWindow("BaseWindow_RootWnd", null);
IntPtr chwnd1 = FindWindowEx(hwnd, IntPtr.Zero, "BaseWindow_RootWnd", null);
IntPtr chwnd2 = FindWindowEx(chwnd1, IntPtr.Zero, "Winamp Gen", null);
IntPtr chwnd3 = FindWindowEx(chwnd2, IntPtr.Zero, "#32770", null);
IntPtr chwnd4 = FindWindowEx(chwnd3, IntPtr.Zero, "Edit", null);
PostMessage(chwnd4, 0x100, 0x43 , 0);
}
}
}
0x43 is the Virtual-Key Code for „C" key.
Thank you very much for your answer.
CatalinPosted Feb 12, 2012, 12:49 PM
I obtained the name of the class using Winspector.
This is what I found with Winspector:
- 000B099A: BaseWindow_RootWnd „Jump to file"
- 00090820: BaseWindow_RootWnd „Jump to file"
- 004E0242: Winamp Gen „Jump to file"
- 001707CC: #32770 „Jump to file"
- 00200806: Edit
I changed my script into this but with no result.
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace WindowsFormsApplication1
{
class Test2
{
[DllImport("User32.Dll", EntryPoint = "PostMessageA")]
static extern bool PostMessage(IntPtr hWnd, uint msg, int wParam, int lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow([MarshalAs(UnmanagedType.LPTStr)] string lpClassName,
[MarshalAs(UnmanagedType.LPTStr)] string lpWindowName);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
public static void comm()
{
IntPtr hwnd = FindWindow("Winamp v1.x", null);
IntPtr chwnd = FindWindowEx(hwnd, IntPtr.Zero, "Edit", null);
PostMessage(chwnd, 0x100, 0x43, 0);
}
}
}
Maybe these are banal questions but I'm very new in c#
Thank you very much for your time.
VulpesPosted Feb 12, 2012, 6:13 AM
CatalinPosted Feb 12, 2012, 3:40 AM
What I want is to send keys to the window (JUMP TO FILE) not to open it. I'm trying to make an application that search a melody in winamp play list by sending keys to this window.
From what I know I have to send keys to a child class of wimamp which is called "Edit", but I don't know how.
I found some examples but it didn't work for me.
I want to use "PostMessage" because I want to be able to sent keys even the window is not in focus.
Thanks.
VulpesPosted Feb 11, 2012, 6:10 PM
http://blog.winamp.com/2008/08/14/keyboard-shortcuts/
the keyboard shortcut for Jump To File is 'J'.
So, I'd send the virtual keycode for 'J' which is 0x4A.