Author Topic: Binding to key up?  (Read 7644 times)

jporkkahtc

  • Senior Community Member
  • Posts: 2620
  • Hero Points: 210
  • Text
Binding to key up?
« on: August 02, 2018, 05:26:47 PM »
Is it possible to bind to key up events?

Specifically, I want to do something while a key is pressed.

I have a key bound to toggle the vertical line for the right margin.
I had an idea: While that key is pressed make the vertical line visible at the current cursor position - allowing me to quickly check vertical alignment over a long span on lines.

I could still do this as a toggle, but I thought it would be neat to have it while the key is pressed.

I suppose I could also map it to while scroll-lock is on (but that interferes with excel).

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2896
  • Hero Points: 153
Re: Binding to key up?
« Reply #1 on: August 02, 2018, 05:35:32 PM »
You could make a command like this maybe and break out when you get a key besides the one you want.

Code: [Select]
_command void test_get_event() name_info(',')
{
   for (i:=0;i<1000;++i) {
      event = get_event();
      eventName := event2name(event);
      if (eventName!="F12") break;
      say('test_get_event got F12');
   }
}

I guess you would probably want to make it an infinite loop, I just made it to 1000 so I was sure I could get out of it  ;)

jporkkahtc

  • Senior Community Member
  • Posts: 2620
  • Hero Points: 210
  • Text
Re: Binding to key up?
« Reply #2 on: August 02, 2018, 06:49:02 PM »
Thanks.
Does SlickC have a sleep() function?

Or, instead of looping 1000 times, loop until elapsed time is > 2 seconds?
Oh! SlickC does have timer callbacks right? So I could set a timer callback to clear the vertical line after a couple of seconds.

For now I decided to just use a simple toggle.
The only problem with the code below is that sometimes the vertical line also appears in search results. Not always, but often.

Why would that be?

Code: [Select]
_command void set_col() name_info(','VSARG2_READ_ONLY|VSARG2_REQUIRES_MDI_EDITORCTL)
{
    _str result = _default_option('R');
    if (result == "0") {
        _default_option('R', p_col-1);
    } else {
        _default_option('R', "0");
    } 
}

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2896
  • Hero Points: 153
Re: Binding to key up?
« Reply #3 on: August 02, 2018, 06:54:42 PM »
Look at the help on delay().