globalmousekeyhook icon indicating copy to clipboard operation
globalmousekeyhook copied to clipboard

InvalidCastExpression Using Example Creating Dictionary<Sequence,Action>

Open tkefauver opened this issue 4 years ago • 2 comments

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 avatar Jul 15 '20 03:07 tkefauver

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

tkefauver avatar Jul 15 '20 04:07 tkefauver

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())); } }

gmaron721 avatar Mar 26 '23 12:03 gmaron721