View Full Version : OnKeyDown method question
MaxBro
04-14-2010, 03:19 PM
Hello! I've implemented this method in IControl.cpp:
void OnKeyDown(int x, int y, int key)
{
.......////some code for doing something
}
But when i run my plugin in host (i've tried ableton live, logic and AU Lab) nothing happens when i press a key.
CC_ maybe you know where the answer is?
I've never tried it, but a from quick grep in the IPlug directory, it looks like it is not implemented on OSX. OnKeyDown is only mentioned in IGraphics.cpp and IGraphicsWin.cpp not in IGraphicsCarbon.cpp or IGraphicsCocoa.mm .
MaxBro
04-15-2010, 07:23 PM
Thanks CC_! Your answer helped!
I've added to IGraphicsCarbon.cpp one more case of eventClass and it works:
switch (eventClass) { //////it is already in the IGraphicsCarbon.cpp
case kEventClassKeyboard: ////this case i've added
{
switch (eventKind) {
case kEventRawKeyDown:{
pGraphicsMac->OnKeyDown( NULL, NULL, NULL);// NULL is just for example here
}
}
}
And we have to add next line in IGraphicsCarbon.cpp:
const EventTypeSpec windowEvents[] = {
{ kEventClassMouse, kEventMouseDown },
{ kEventClassMouse, kEventMouseUp },
{ kEventClassMouse, kEventMouseMoved },
{ kEventClassMouse, kEventMouseDragged },
{ kEventClassMouse, kEventMouseWheelMoved },
{ kEventClassKeyboard, kEventRawKeyDown} //// <----this line was added
};
Now, when any key is pressed, IPlugExample will call OnKeyDown method. If we need to know, what key is pressed, we need to add following line into "case kEventRawKeyDown":
GetEventParameter(pEvent, kEventParamKeyCode,
typeUInt32, NULL, sizeof(UInt32), NULL, &ch);
Now "ch" is the key.
MaxBro
04-16-2010, 06:39 AM
Today I've tested this method in Logic, and Live. Unfortunately it works only with simple Audio Unit Hosting. It seems to me, that Logic and Live doesn't pass keyboard events to plugin. So, is there any other ideas how to implement computer keyboard?
P.S. I need this for adjust parametеrs with arrow keys, as do the waves plugins.
That might be because those hosts use Cocoa windows rather than Carbon windows. To cover all hosts you will need to implement the methods in IGraphicsCocoa.mm as well.
MaxBro
04-18-2010, 02:26 PM
I've tried this method in ableton live 7 and it doesn't work. As I know live 7 doesn't support cocoa interfaces.
MaxBro
04-19-2010, 07:59 AM
Ok. CC_ you are right. I've added this to IGraphicsCocoa.mm:
/////////////////////////////////////////////////////////////////////////////////
- (void)keyDown: (NSEvent *)theEvent
{
NSString *characters;
unsigned int characterIndex, characterCount;
characters = [theEvent charactersIgnoringModifiers];
characterCount = [characters length];
for (characterIndex = 0; characterIndex < characterCount; characterIndex++) {
[self doEventForCharacter:[characters characterAtIndex:characterIndex] downEvent:YES];
}
}
- (void)doEventForCharacter: (unichar)character downEvent: (BOOL)flag
{
unsigned long bit;
bit = 0;
switch(character)
{
case 's':
mGraphics->OnKeyDown(0, 0, 0);
break;
}
}
/////////////////////////////////////////////////////////////////////////////////
And it works both in Logic 9 and Ableton 8. Now, when I press the "s" key on keyboard IPlug calls OnKeyDown method.
That's good! I was going to check it myself but I didn't get time yet. It looks like you are pretty close to being able to duplicate the behaviour of the Windows WM_KEYDOWN case in IGraphicsWin.cpp .
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.