| |

VerySource

 Forgot password?
 Register
Search
View: 1111|Reply: 7

How to receive keyboard events?

[Copy link]

1

Threads

5

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-12-17 11:30:01
| Show all posts |Read mode
Select an object in the form

Press the Delete key or Backspace key to delete

How to receive key events?

Thanks!
Reply

Use magic Report

0

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-12-18 13:45:01
| Show all posts
keydown event
if e.KeyCode=keys.delete or e.keycode=keys.Back then
...
end if
Reply

Use magic Report

0

Threads

14

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-12-18 22:00:01
| Show all posts
And to set the KeyPreview property of the form to True
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-12-20 21:30:01
| Show all posts
You can use the keydown event, the same as the second floor. If you use the keypass event, you must perform character conversion for comparison, and you can only capture backspace but not delete.
e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Back)
Reply

Use magic Report

0

Threads

11

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-12-20 21:45:01
| Show all posts
In the keypass event: e.KeyChar = ChrW(8) refers to the backspace, check the ascii code of delete, and then the same
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-12-20 22:00:02
| Show all posts
The keydown event is useful in this form. If you want to monitor the keyboard, it is recommended to use a hook.
Reply

Use magic Report

0

Threads

11

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-12-20 22:15:01
| Show all posts
del is 16

if is 8 or is 16 then
  delete
endif
Reply

Use magic Report

0

Threads

11

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-12-20 22:30:01
| Show all posts
Sorry, wrong, del is 46
In fact, it can be written in keyup
    If e.KeyCode = Keys.Delete orelse e.KeyCode = Keys.backspace Then
       deleteobj()
    endif
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list