Hi,
I would like to emulate a key press on a small music player ; I will make a new plugin for that purpose.
Example, I am searching codes for "X", "A", "Ctrl-X", "L", ...
I intend to use the SendMessage function but I dont know the LParam and HParam values.
Who knows ?
Please advice.
Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details
If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.
If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.
Simulate a key press
Re: Simulate a key press
For example Meedio and MediaPortal plugins work by sending windows messages using SendMessage to the target application. On the other hand for example the PowerDVD plugin sends keypresses to the application using SendKeys.
It sounds to me like you are trying to send actual key presses, same thing as if you press your keyboard hotkeys, so I'd recommend you to take a look at the PowerDVD plugin for a clean example.
If you really wanted to use SendMessage method (which I don't think is the case here) then you have to start by first finding out the control ID's you want to trigger. The LParam and WParam can be anything the programmer has used for his controls when he was making the application. Usually not much attention is paid to what these values actually are since mostly they are not directly needed but rather they are used by Windows itself so that whenever you push a button etc. a message is automatically dispatched to the application, whis just is how the Windows UI works. Probably even the person who made the program doesn't know what the ID's for everything are without looking it up. This means often the only way to find out is by poking around the program with something like winspector or Spy++. It will take time and I woulndn't recommend it to anybody except experienced users as you need to have a good grip on how computer programs work in general.
I hope that helped! If you have more questions just ask away.
-jinxdone
It sounds to me like you are trying to send actual key presses, same thing as if you press your keyboard hotkeys, so I'd recommend you to take a look at the PowerDVD plugin for a clean example.
If you really wanted to use SendMessage method (which I don't think is the case here) then you have to start by first finding out the control ID's you want to trigger. The LParam and WParam can be anything the programmer has used for his controls when he was making the application. Usually not much attention is paid to what these values actually are since mostly they are not directly needed but rather they are used by Windows itself so that whenever you push a button etc. a message is automatically dispatched to the application, whis just is how the Windows UI works. Probably even the person who made the program doesn't know what the ID's for everything are without looking it up. This means often the only way to find out is by poking around the program with something like winspector or Spy++. It will take time and I woulndn't recommend it to anybody except experienced users as you need to have a good grip on how computer programs work in general.
I hope that helped! If you have more questions just ask away.
-jinxdone
Re: Simulate a key press
Yes it helps very much.
Gonna take a look at PowerDVD plugin...
Thanks again.
Gonna take a look at PowerDVD plugin...
Thanks again.
Re: Simulate a key press
Hi,
I am sorry, but I don't know very well Python language.
In consequence, I don't find over the web a clear and simple example with the SendKeys functions.
Could someone give an example please ?
Best Regards.
I am sorry, but I don't know very well Python language.
In consequence, I don't find over the web a clear and simple example with the SendKeys functions.
Could someone give an example please ?
Best Regards.
Re: Simulate a key press
Below is what I've been using, where I've added some comments. Except for the ACTIONS variable, you should replace everything in CAPS.
Good luck,
Brett
Code: Select all
version="0.1"
# Plugins/NAME/__init__.py
#Basic registration
eg.RegisterPlugin(
name = "NAME",
author = "AUTHOR",
version = version,
kind = "program",
description = (
'DESCRIPTION.'
),
createMacrosOnAdd = False,
icon = (
"iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsTAAALEwEA"
"mpwYAAABNmlDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjarY6xSsNQFEDPi6LiUCsE"
"cXB4kygotupgxqQtRRCs1SHJ1qShSmkSXl7VfoSjWwcXd7/AyVFwUPwC/0Bx6uAQIYOD"
"CJ7p3MPlcsGo2HWnYZRhEGvVbjrS9Xw5+8QMUwDQCbPUbrUOAOIkjvjB5ysC4HnTrjsN"
"/sZ8mCoNTIDtbpSFICpA/0KnGsQYMIN+qkHcAaY6addAPAClXu4vQCnI/Q0oKdfzQXwA"
"Zs/1fDDmADPIfQUwdXSpAWpJOlJnvVMtq5ZlSbubBJE8HmU6GmRyPw4TlSaqo6MukP8H"
"wGK+2G46cq1qWXvr/DOu58vc3o8QgFh6LFpBOFTn3yqMnd/n4sZ4GQ5vYXpStN0ruNmA"
"heuirVahvAX34y/Axk/96FpP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aIKxTIyNu3dQ127wx2+/4Pk+"
"qaRCMp1lemYBIQApK57Ic1mbZiKMooAUg5gYkHd32Hv0E9//uMHocIaBAZlsOonZ7+B0"
"ugxnkhT3JUnI5bKridy56cTZWeKJBBHZw2hVOX62hSxCJBrBMAwc26bb7eK6Lr7vYTsu"
"8Xii9/8Ah4utvl5bVpIAAAAASUVORK5CYII="
)
)
#NEED TO SET THIS UP TO FIND YOUR WINDOW
#Plugin won't compile without this setup, so FIX and UNCOMMENT this line
#FindPROG = eg.WindowMatcher(u'PROGNAME IN TASK MANAGER{*}', None, None, None, None, 1, False, 0.0, 0)
#My generic function
#AddActionsFromList creates a new instance with a different self.name and self.value for
#each line in the ACTIONS list
class hotKeys(eg.ActionClass):
def __call__(self):
hwnds = FindPROG()
if len(hwnds) != 0:
eg.SendKeys(hwnds[0], self.value, False)
else:
self.PrintError("ERROR")
return
#Here's my list of keystrokes, and what they do
#u set's to unicode, the brackets are the sequence. I don't think you can have spaces
#in the brackets.
ACTIONS = (
(hotKeys, 'Play', 'Play', 'Play', u'{Space}'),
(hotKeys, 'Pause', 'Pause', 'Pause/Play', u'{Space}'),
(hotKeys, 'Stop', 'Stop', 'Stop', u'{O}'),
(hotKeys, 'Up', 'Up', 'Up', u'{Up}'),
(hotKeys, 'Down', 'Down', 'Down', u'{Down}'),
(hotKeys, 'Left', 'Left', 'Left', u'{Left}'),
(hotKeys, 'Right', 'Right', 'Right', u'{Right}'),
)
#Very simple class to instantiate the ACTIONS
class TMT(eg.PluginClass):
def __init__(self):
self.AddActionsFromList(ACTIONS)
Brett