Page 1 of 2

Python,; KeyError; Volumeup

Posted: Mon Dec 28, 2009 9:58 pm
by Kindt.nick
Hi,

I'm currently writing a python script so I can change te volume with an exponential curve.
I've sort of done it, but now I' want to embed the keystrokes into that python script.

I've googled my ass off and still can't seem to figure it out:
When I use:
__ if eg.plugins.Keyboard.VolumeDown:
__ ...

I get:
__ Traceback (most recent call last):
__ Python script "63", line 15, in <module>
__ if eg.plugins.Keyboard.VolumeDown:
__ File "C:\Program Files\EventGhost\eg\Classes\PluginInfo.py", line 39, in __getattr__
__ KeyError: 'VolumeDown'

The keyboard pluging is loaded, but
Same for the MceRemote.VolumeDown, MceRemote.Mute, etc
I can't seem to figure out what the syntax is...

Thx, in advance,
Nick

Re: Python,; KeyError; Volumeup

Posted: Mon Dec 28, 2009 10:52 pm
by jitterjames
I'm not exactly sure what you are trying to do but I don't see how
eg.plugins.Keyboard.VolumeDown
would evaluate to a boolean. The keyboard plugin is used to generate events so I don't think you can call it like a function and therefore it won't return a boolean value. Am I missing something here?

You should probably be using the keyboard plugin to generate the event that executes your python script. After that I would expect you to be calling another plugin to adjust the volume or something.

maybe this will help:
http://www.eventghost.org/forum/viewtop ... lit=smooth

or maybe you want to use the autorepeat function combined with a global variable? I'm not exactly sure what you are trying to do since you just say "change te volume with an exponential curve" which could mean a few things.

hope this may help...

Re: Python,; KeyError; Volumeup

Posted: Mon Dec 28, 2009 11:41 pm
by Kindt.nick
Hey, thx for your reply,

So, what you is is that it is not possible to check in a Python script wether a key is pressed or not?

Thx,
Nick

Re: Python,; KeyError; Volumeup

Posted: Tue Dec 29, 2009 2:49 am
by jitterjames
I don't think it's possible, but if it is it would probably be more complicated than that. Maybe if you explain more clearly what you are trying to do someone might be able to make a suggestion.

Re: Python,; KeyError; Volumeup

Posted: Tue Dec 29, 2009 2:55 pm
by Kindt.nick
I would like to just have 1 python script for the volume.
This script should be activated by the following keys;
- Keyboard.Volumeup
- Keyboard.VolumeDown
- Keyboard.Mute
- MceRemote.Volumeup
- MceRemote.VolumeDown
- MceRemote.Mute

Below that should be the python script.
And it is withtin the python script that it should be determined
what action should be taken.

Eventually my goal is to just have one python script that is constantly running
so no keyevents above it in the tree and that everything is determend in the script.


thx,
Nick

Re: Python,; KeyError; Volumeup

Posted: Tue Dec 29, 2009 3:33 pm
by jitterjames
I don't really think that's possible. More importantly I don't see the point in doing it. It sounds like you are trying to remove the "event" part of a program called event ghost!

What you want to do is simple and elegantly handled by the programs basic functionality without having to write any python code.

Even if you wanted to use python to determine what action to perform, you would still need to place events for each of those keypresses in the macro that triggers the macro... but again, why bother since it defeats the purpose of the program.

Re: Python,; KeyError; Volumeup

Posted: Tue Dec 29, 2009 4:21 pm
by Bartman
Kindt.nick wrote:I would like to just have 1 python script for the volume.
This script should be activated by the following keys;
- Keyboard.Volumeup
- Keyboard.VolumeDown
- Keyboard.Mute
- MceRemote.Volumeup
- MceRemote.VolumeDown
- MceRemote.Mute
Just add those events to the Skript and you are done.

Re: Python,; KeyError; Volumeup

Posted: Tue Dec 29, 2009 8:42 pm
by Kindt.nick
Bartman wrote:
Kindt.nick wrote:I would like to just have 1 python script for the volume.
This script should be activated by the following keys;
- Keyboard.Volumeup
- Keyboard.VolumeDown
- Keyboard.Mute
- MceRemote.Volumeup
- MceRemote.VolumeDown
- MceRemote.Mute
Just add those events to the Skript and you are done.
Hi,

Already tried to add this inside the script:
If Keyboard.Volumeup == true :
j = j+1

Doesn't work.

My problem is that I can't seem to find any documentation about what the Volumeup variable is.
Is it a long, bool, etc? and how can I read the value of them?

thx,
Nick

Re: Python,; KeyError; Volumeup

Posted: Tue Dec 29, 2009 9:05 pm
by jitterjames
ok I think I know what you are looking for.

try these:
print eg.event.prefix
print eg.event.suffix
print eg.event.string

I think this is the page you are looking for here:
http://www.eventghost.org/docs/eg/eg.Ev ... Event.html

Re: Python,; KeyError; Volumeup

Posted: Tue Dec 29, 2009 10:16 pm
by Kindt.nick
THX!

Now I understand the purpuse of the "eg.event."- syntax.
I thought is was something completely else.

< if eg.event.string == 'MceRemote.VolumeDwn': > dit the trick

thx,
Nick

Re: Python,; KeyError; Volumeup

Posted: Wed Dec 30, 2009 1:01 am
by Kindt.nick
Another question,

I've written the script now,
is it possible to run continually?

What I mean is, IÔÇÖve written the script in a way that it skips automatically all the code untill there the correct key is pressed. (volumeup, down, mute, etc)

I just think it is more neat to just have the script in there in stead of
the script and above it, 6 different events above is.

Or do I have to make it a plugin to make it work like this?

I've tried copying it to the auto start section, but it does not see the key pressed anymore.
Any other way to that a key is pressed besides the eg.event.string?

Thx,
Nick

Re: Python,; KeyError; Volumeup

Posted: Wed Dec 30, 2009 2:19 am
by jitterjames
welcome to the 20th century. Event driven code is good. Let the events activate your script when necessary.

What do you want to do, have a loop running continually eating up 100% of your cpu resources? This makes no sense to me.

Re: Python,; KeyError; Volumeup

Posted: Wed Dec 30, 2009 9:03 am
by Bartman
To have a smooth volume change the script has to pause between the changes, so it won't eat up all cpu.

Re: Python,; KeyError; Volumeup

Posted: Wed Dec 30, 2009 2:23 pm
by Kindt.nick
jitterjames wrote:welcome to the 20th century. Event driven code is good. Let the events activate your script when necessary.

What do you want to do, have a loop running continually eating up 100% of your cpu resources? This makes no sense to me.

"21th century." It's not that I'm some sort of dumbass, I've been programming for years now, but only embedded devices.
I know that you've got to look at some things from a different angle, I've you're not on embedded devices,
but still, it makes sense to me if you write this in the beginning;
_ if not eg.event.string == 'MceRemote.VolumeDwn':
_ exit

it wil only take a minimum of time to run, so a minimum of resource will be taken, not?
Bartman wrote:To have a smooth volume change the script has to pause between the changes, so it won't eat up all cpu.
Windows is a multitask OS, so eventghost (and the script) will 'pause' automatically between changes, not?
Of not, how do I do that? I've read somewhere to make is threaded?

Re: Python,; KeyError; Volumeup

Posted: Wed Dec 30, 2009 2:24 pm
by Kindt.nick
jitterjames wrote:welcome to the 20th century. Event driven code is good. Let the events activate your script when necessary.

What do you want to do, have a loop running continually eating up 100% of your cpu resources? This makes no sense to me.
"21th century." It's not that I'm some sort of dumbass, I've been programming for years now, but only embedded devices.
I know that you've got to look at some things from a different angle, I've you're not on embedded devices,
but still, it makes sense to me if you write this in the beginning;
_ if not eg.event.string == 'MceRemote.VolumeDwn':
_ exit

it wil only take a minimum of time to run, so a minimum of resource will be taken, not?
Bartman wrote:To have a smooth volume change the script has to pause between the changes, so it won't eat up all cpu.
Windows is a multitask OS, so eventghost (and the script) will 'pause' automatically between changes, not?
Of not, how do I do that? I've read somewhere to make is threaded?