By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,373 Members | 1,792 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,373 IT Pros & Developers. It's quick & easy.

Pasting from clipboard with F12

100+
P: 133
I want to paste from clipboard with the F12 key please give some examples because i cannot uderstand any Key Remapping i have read.
Jan 22 '08 #1
Share this Question
Share on Google+
12 Replies


kadghar
Expert 100+
P: 1,295
I want to paste from clipboard with the F12 key please give some examples because i cannot uderstand any Key Remapping i have read.
In the KeyDown event write something like:

Expand|Select|Wrap|Line Numbers
  1. if KeyCode = 123 then
  2.    '[your paste code]
  3. end if
that should do for your application. (even then, it could have some advantages to use the KeyUp event or saving the KeyCode in a public variable and write the paste code in the KeyPress event, but that's up to what you need).
Jan 22 '08 #2

100+
P: 133
In the KeyDown event write something like:

Expand|Select|Wrap|Line Numbers
  1. if KeyCode = 123 then
  2.    '[your paste code]
  3. end if
that should do for your application. (even then, it could have some advantages to use the KeyUp event or saving the KeyCode in a public variable and write the paste code in the KeyPress event, but that's up to what you need).

Thanks for your prompt reply but i am unsure about the syntax of pasting to what ever is selected , Do i use Clipboard.GetText ? if so how.

Thanks for your help :)
Gobble.
Jan 22 '08 #3

kadghar
Expert 100+
P: 1,295
Thanks for your prompt reply but i am unsure about the syntax of pasting to what ever is selected , Do i use Clipboard.GetText ? if so how.

Thanks for your help :)
Gobble.
well, it depends on what you've selected, if its a textbox, something like:
textbox1.paste
should be enough.
Remember the keydown event occurs when the control or form has the focus and you press any key, so you'll have to write something in the controls' keydown event, that you want to have this feature.

Now, if what you want is a little program that 'remaps the keyboard' all the time, that'll probably need a Timer that read the keyboard events. But i dont think we need to complicate it if a single line:

Expand|Select|Wrap|Line Numbers
  1. if keycode=123 then textbox1.paste
in each textbox keydown event will do.
Jan 22 '08 #4

Expert 5K+
P: 8,434
I want to paste from clipboard with the F12 key please give some examples because i cannot uderstand any Key Remapping i have read.
What version of VB are we dealing with? I've never heard of a Paste method on textboxes, so presumably that's a later version than what I'm using.

Also, what is that actual issue here - the pasting, or detecting the function key?
Jan 22 '08 #5

100+
P: 133
well, it depends on what you've selected, if its a textbox, something like:
textbox1.paste
should be enough.
Remember the keydown event occurs when the control or form has the focus and you press any key, so you'll have to write something in the controls' keydown event, that you want to have this feature.

Now, if what you want is a little program that 'remaps the keyboard' all the time, that'll probably need a Timer that read the keyboard events. But i dont think we need to complicate it if a single line:

Expand|Select|Wrap|Line Numbers
  1. if keycode=123 then textbox1.paste
in each textbox keydown event will do.

Thanks for the reply's guys,
ok ill explain it a little better basicly i am copying text from a txt file to the clipboard, Then i want to be able to paste it to any input box the mouse has selected.on.

ohh btw using VB6
Thanks Gobble.
Jan 23 '08 #6

Expert 5K+
P: 8,434
Try something like this...

Expand|Select|Wrap|Line Numbers
  1. Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
  2.   If KeyCode = vbKeyF12 Then
  3.     Text1 = Clipboard.GetText
  4.   End If
  5. End Sub
  6.  
This is a very simple version, of course. You might want to do the work in a sub somehwre, and you may want to do different processing depending on things like whether the user has selected part of the text in the textbox.

It may also be nicer to do it from the form's KeyDown event rather than coding it individually for each textbox. But that will be slightly more complex to load, since you'd need to know which control has the focus.
Jan 23 '08 #7

QVeen72
Expert 100+
P: 1,445
Hi,

OK, First make Form's Property : KeyPreview = True.
Say When user Selects a Control and Presses "F8". you copy the contents to the selcetd Control..
Write this code in KeyUp event of the Form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
  2.     If KeyCode = vbKeyF8 Then
  3.         Dim ctl As Control
  4.         Set ctl = Me.ActiveControl
  5.         If TypeOf ctl Is TextBox Then
  6.             ctl.text = Clipboard.GetText
  7.         ElseIf TypeOf ctl Is Label Then
  8.             ctl.Caption = Clipboard.GetText
  9.         End If
  10.     End If
  11. End Sub
  12.  
Regards
Veena
Jan 23 '08 #8

100+
P: 133
Hi,

OK, First make Form's Property : KeyPreview = True.
Say When user Selects a Control and Presses "F8". you copy the contents to the selcetd Control..
Write this code in KeyUp event of the Form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
  2.     If KeyCode = vbKeyF8 Then
  3.         Dim ctl As Control
  4.         Set ctl = Me.ActiveControl
  5.         If TypeOf ctl Is TextBox Then
  6.             ctl.text = Clipboard.GetText
  7.         ElseIf TypeOf ctl Is Label Then
  8.             ctl.Caption = Clipboard.GetText
  9.         End If
  10.     End If
  11. End Sub
  12.  
Regards
Veena

Thank you so much guys i have learned from your examples ,Thanks for all your time in helping me much appreciated.

Gobble.
Jan 23 '08 #9

100+
P: 133
Thank you so much guys i have learned from your examples ,Thanks for all your time in helping me much appreciated.

Gobble.

Ok stuck again i got it to paste within my program's textbox but i want to be able to paste it onto anything with the Fkey.
For example . paste onto an open notepad or paste into explorer ect.

Thanks again
Gobble.
Jan 23 '08 #10

QVeen72
Expert 100+
P: 1,445
Hi,

You can code, to paste it on VB Controls, as you can tap the Events..
But, outside VB, you cant code...
use Ctrl+V.. thats all..

Regards
Veena
Jan 23 '08 #11

100+
P: 133
Hi,

You can code, to paste it on VB Controls, as you can tap the Events..
But, outside VB, you cant code...
use Ctrl+V.. thats all..

Regards
Veena
oh ok thanks :)
Gobble.
Jan 23 '08 #12

Expert 5K+
P: 8,434
oh ok thanks :)
Gobble.
Note that you can use SendKeys to "pretend" the user pressed Ctrl-V.
Jan 24 '08 #13

Post your reply

Sign in to post your reply or Sign up for a free account.