C# Detect detect key down after button click -


i perform action after particular key pressed after button click. sth this: click button press end key , action performed.

i tried simple code doesn't work.

private void buttonstart_click(object sender, eventargs e)     {         keydown += onkeydown;              }      private void onkeydown(object sender, keyeventargs keyeventargs)     {         if (keyeventargs.keycode == keys.return)             label2.text = "siala";     } } 

you did not specify whether using winforms or wpf,
following example wpf should similar winforms well:

bool canclick = true;  public mainwindow() {     initializecomponent();     thebox.previewmousedown += thegrid_previewmousedown;           }  async void thegrid_previewmousedown(object sender, mousebuttoneventargs e) {                 if (canclick)     {         canclick = false;         thebox.previewkeydown += thegrid_previewkeydown;                         await task.delay(5000);         thebox.previewkeydown -= thegrid_previewkeydown;         canclick = true;     } }  void thegrid_previewkeydown(object sender, keyeventargs e) {     console.writeline("button {0}", e.key); } 

the idea here register event handler previewkeydown when
mouse clicked , remove handler after 5 seconds.

this way user have enter key within 5 seconds of clicking mouse.
boolean used make sure event handler isn't registered more once per time.

you should reactive extensions might provide cleaner
way of solving problem.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -