gmamaladze / globalmousekeyhook

This library allows you to tap keyboard and mouse, detect and record their activity even when an application is inactive and runs in background.
MIT License
1.05k stars 257 forks source link

InvalidCastExpression Using Example Creating Dictionary<Sequence,Action> #127

Open tkefauver opened 4 years ago

tkefauver commented 4 years ago

Following the example I'm creating a Dictionary<Sequence,Action> like this: ShowMainWindowSequence = Sequence.FromString("Control+Shift+D"); HideMainWindowSequence = Sequence.FromString("Escape"); var assignment = new Dictionary<Sequence, Action>{ {ShowMainWindowSequence, ()=>Console.WriteLine("No!")}, {HideMainWindowSequence, ()=>Console.WriteLine("rename2")} };

Then receive the following error during runtime: System.InvalidCastException: 'Unable to cast object of type 'Gma.System.MouseKeyHook.Sequence' to type 'Gma.System.MouseKeyHook.Combination'.'

Those variables are definitely Sequences and not Combinations so I'm pretty stumped at what the issue is, any idea? A new bug possibly?

tkefauver commented 4 years ago

I think I figured out the issue its because it uses single combinations but the example says that's ok so maybe that's a bug? Great library though, its a huge help

gmaron721 commented 1 year ago

I am getting the same error. When the loop goes to 2

var sequences = new Dictionary<Sequence, Action>(); for (int i = 1; i <= 1; i++) { for (int j = 0; j <= 9; j++) { int bufferIndex = (i * 10) + j; sequences.Add(Sequence.FromString($"Control + D{i}, D{j}"), () => ActionSelectBuffer(bufferIndex.ToString())); } }