# Vruby Question on Processing Keyboard Input

**URL:** <https://www.ruby-forum.com/t/vruby-question-on-processing-keyboard-input/77419>\
**Category:** Ruby\
**Created:** [November 27, 2006, 9:06pm UTC](https://www.ruby-forum.com/t/vruby-question-on-processing-keyboard-input/77419 "2006-11-27T21:06:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 27, 2006, 9:06pm UTC](https://www.ruby-forum.com/t/vruby-question-on-processing-keyboard-input/77419/1 "2006-11-27T21:06:35Z")

</div>

I am new to Ruby and even newer to vruby so bear with me. I have a  
simple application that has a text box. I would like to track when the  
user hits Ctrl-C, Ctrl-X, Ctrl-A and Ctrl-V so that my program behaves  
the same way other windows program do.

I have looked at the vruby documentation and samples but have not found  
anything that explains how to do this.

Any help would be greatly appreciated.

thanks,

Luis

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 28, 2006, 1:00pm UTC](https://www.ruby-forum.com/t/vruby-question-on-processing-keyboard-input/77419/2 "2006-11-28T13:00:44Z")

</div>

> … I would like to track when the  
> user hits Ctrl-C, Ctrl-X, Ctrl-A and Ctrl-V so that my program behaves  
> the same way other windows program do.

Does Ctrl-C, Ctrl-X and Ctrl-V already work “out of the box”? (I think  
so.)

- Axel

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 28, 2006, 1:50pm UTC](https://www.ruby-forum.com/t/vruby-question-on-processing-keyboard-input/77419/3 "2006-11-28T13:50:52Z")

</div>

I wish it would. As far a I understand you have to write code to handle  
the keyboard events and capture when a user uses a particular key or  
keys.

Luis

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 28, 2006, 4:11pm UTC](https://www.ruby-forum.com/t/vruby-question-on-processing-keyboard-input/77419/4 "2006-11-28T16:11:17Z")

</div>

I found the script. Thanks for the tip. But the script only handles  
single key presses. It does not handle key combinations. It does get me  
closer to a solution though.

thanks,

Luis

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 28, 2006, 2:00pm UTC](https://www.ruby-forum.com/t/vruby-question-on-processing-keyboard-input/77419/5 "2006-11-28T14:00:54Z")

</div>

> I wish it would. As far a I understand you have to write code to handle  
> the keyboard events and capture when a user uses a particular key or  
> keys.

Hmm, some years ago, I wrote a little application using vruby. I just  
started it, and there is an edit box in it and I can copy and paste  
text with Ctrl-C and Ctrl-V. I’did not code anything special for  
making it work. One thing I remember is, that I had to change “oemfont”  
or something like this, but I think, this was not neccessary in order  
to get Ctrl-C… working.

BTW, “subclstest.rb” in the samples dir could be interesting. (But I  
think, it is not neccessary for what you want.) Do you have/find it?

- Axel

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 28, 2006, 4:51pm UTC](https://www.ruby-forum.com/t/vruby-question-on-processing-keyboard-input/77419/6 "2006-11-28T16:51:24Z")

</div>

Could you post your code, or part of it?

And, is it right, that you just want to copy and paste text within your  
editbox or from another Windows app to/from your vruby editbox, using  
Ctrl-C, X, Z?

- Axel

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 28, 2006, 5:47pm UTC](https://www.ruby-forum.com/t/vruby-question-on-processing-keyboard-input/77419/7 "2006-11-28T17:47:36Z")

</div>

removed\_email\_address@domain.invalid wrote:

> I found the script. Thanks for the tip. But the script only handles  
> single key presses. It does not handle key combinations. It does get me  
> closer to a solution though.

But Ctrl+C, Ctrl+V and others count as keypresses, as input characters.  
You  
can detect and act on these user entries, just as though they were  
normal  
letters.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [November 28, 2006, 8:12pm UTC](https://www.ruby-forum.com/t/vruby-question-on-processing-keyboard-input/77419/8 "2006-11-28T20:12:14Z")

</div>

After taking a closer look at the program I noticed that Ctrl-C, Ctrl-X  
and Ctrl-V work. The only one that does not work is Ctrl-A. Here’s a  
sample of the code

require ‘vr/vruby’  
require ‘vr/vrcontrol’  
require ‘vr/vrcomctl’  
require ‘vr/vrtooltip’

class TestForm \<VRForm

def construct  
self.caption = ‘NFL Stats’  
self.move(140,124,760,531)

```
addControl(VRText,'text1',"",16,16,725,350,WStyle::WS_VSCROLL)

```

end

end

VRLocalScreen.start(TestForm)
