Ctrl+Key combination not working properly

I’m trying to set a combination of key (ctrl+G and ctrl+F), but the ctrl+F doens’t answer properly : the combination works only if i press F then ctrl, and i can’t find a way to make it work in the reverse. does anyone have an idea ?

    if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.G))
    {
        Debug.Log("Ctrl+G");
        GameObject[] objects = Utilitaires.FindSelectedObjects();
        for (int i = 0; i < objects.Length; i++)
        {
            variables o1 = (variables)objects*.GetComponent("variables");*

if (o1 != null)
{
o1.setMyObjectsGroup(objects);
}
}
}
if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyUp(KeyCode.F))
{
Debug.Log(“Ctrl+F”);
GameObject[] objects = Utilitaires.FindSelectedObjects();
for (int i = 0; i < objects.Length; i++)
{
GameObject[] thisObject = new GameObject[1];
thisObject[0] = objects*;*
variables o2 = (variables)objects*.GetComponent(“variables”);*
if (o2 != null)
{
o2.setMyObjectsGroup(thisObject);
o2.unselect();
}
}
}

I never tried this, but it might help to cache the ctrl key manually:

bool leftControl = false;

if(Input.GetKeyDown(KeyCode.LeftControl))
    leftControl = true;
if(Input.GetKeyUp(KeyCode.LeftControl))
    leftControl = false;

if (leftControl && Input.GetKeyUp(KeyCode.F))
{
    // ...

This way the control state is based on events rather than the state (wherever Unity is reading it from).

Btw, this looks like you need that in the editor, right? if so, where are you executing the code? Keep in mind that some keys can’t really be used in the editor, or should be avoided since they already have another function.

To get key combinations, you need to use the Event class in OnGUI(). This post as some scripts that demonstrate:

http://answers.unity3d.com/questions/49285/how-can-i-get-a-combination-of-keys-pressed.html

Your code for F is looking for the key to be released, your code for G is looking for the key to be pressed - I’m wondering if that is your problem?