1
00:00:01,680 --> 00:00:06,840
Hi, welcome back in this video, I'll show you how to control the computer keyboards via Python.

2
00:00:07,050 --> 00:00:15,540
So basically, we will instruct Python to press keys and type in text automatically.

3
00:00:15,780 --> 00:00:16,230
Let's do.

4
00:00:16,230 --> 00:00:19,050
That's using PUOi all target.

5
00:00:19,070 --> 00:00:24,000
So if you didn't follow the previous lecture on how to control the mouse, you should do that first,

6
00:00:24,390 --> 00:00:32,100
because there are some things which are related, such as we want to get the position of the cursor

7
00:00:32,400 --> 00:00:40,310
because what I be doing now practically is, you see, I have this simple text file here in my project

8
00:00:40,350 --> 00:00:45,780
for you, so please make sure you have created a file and it's somewhere in here.

9
00:00:46,380 --> 00:00:53,550
So this is just the text file or what I would be doing is, ah, we will instruct Python to go here.

10
00:00:53,790 --> 00:01:01,260
Double click this file of press the down arrow key to go to the end of the line and then press the enter

11
00:01:01,260 --> 00:01:04,410
key and then type in something in here.

12
00:01:04,920 --> 00:01:06,870
So Python will do all of that.

13
00:01:07,560 --> 00:01:10,290
Let me show you step by step how this can be done.

14
00:01:10,770 --> 00:01:14,580
So the first action is to double click the sample.

15
00:01:14,580 --> 00:01:17,430
The text file to often needs to be able to do that.

16
00:01:17,430 --> 00:01:22,560
We need to know the position of this file here in the current view.

17
00:01:22,950 --> 00:01:26,010
So for that, we would use.

18
00:01:28,810 --> 00:01:31,780
P y all together that position.

19
00:01:34,830 --> 00:01:42,120
And we print out the position two seats on the terminal to the vets file and then execute the codes

20
00:01:42,120 --> 00:01:44,990
using your keyboard to notes your cursor.

21
00:01:45,000 --> 00:01:47,370
So instead of going there, you should use.

22
00:01:47,580 --> 00:01:55,230
In my case, the shortcuts control are so go to the file control or and I execute this keyboard.

23
00:01:55,230 --> 00:01:56,130
That's beautiful.

24
00:01:56,370 --> 00:01:57,990
And that's keyboard that I file with.

25
00:01:57,990 --> 00:02:02,340
Tell me the current position of the cursor, which was in the sampled up to use default.

26
00:02:02,670 --> 00:02:05,730
So 130 to 200, then I want to.

27
00:02:08,590 --> 00:02:09,460
Double click.

28
00:02:10,500 --> 00:02:16,740
A vet's position, 150 to 200, so if I run the script now.

29
00:02:17,900 --> 00:02:23,060
It doesn't matter, either with keyboards or with a cursor by pressing the wrong button.

30
00:02:23,510 --> 00:02:34,190
The screen now opens up samples of text here on my I.D. So the double click was successful, but the

31
00:02:34,210 --> 00:02:40,430
next what we want to do is, well, sometimes the cursor could be here or here or there.

32
00:02:41,000 --> 00:02:48,140
So we want to go to the end of the line of this file of this text one to go to the ends.

33
00:02:48,140 --> 00:02:49,280
We can press that down.

34
00:02:49,280 --> 00:02:50,810
Arrow key, right?

35
00:02:51,380 --> 00:02:57,740
So let's instruct Python to press the down arrow key to go to the ends of the text file using.

36
00:02:59,170 --> 00:03:08,110
The press button, the press button now expects from us to answer one of the keyboard's keys, for example,

37
00:03:08,530 --> 00:03:12,580
Don, which means that Donald Arrow key, see what will happen now.

38
00:03:13,660 --> 00:03:14,620
I run the script.

39
00:03:15,640 --> 00:03:20,590
And Python goes to the file, it opens it and then goes to the ends.

40
00:03:20,800 --> 00:03:25,180
Let's do it in a more slow motion fashion.

41
00:03:25,210 --> 00:03:27,610
To do that, we can import time.

42
00:03:28,100 --> 00:03:34,110
And then after we double click, we say time to sleep and we wait for a second.

43
00:03:34,150 --> 00:03:38,770
For example, and then we President Arrow Key so that we can see what's going on.

44
00:03:40,340 --> 00:03:43,910
But first, let me put the cursor in here after Pierce.

45
00:03:45,570 --> 00:03:47,970
Of Van Gogh, two keyboards for Ronit.

46
00:03:49,700 --> 00:03:54,530
The file opens up and the cursor then goes off one second, it goes to the end of the file.

47
00:03:54,830 --> 00:03:55,430
Now let's.

48
00:04:00,460 --> 00:04:05,350
Press enter after pressing the down arrow bottom.

49
00:04:06,750 --> 00:04:07,590
Execute again.

50
00:04:09,080 --> 00:04:14,360
Enter, a new line is created here now we can write some code, some text.

51
00:04:15,880 --> 00:04:21,910
To write text, to type in text, you use the right methods, not the press methods.

52
00:04:22,270 --> 00:04:29,290
So there is a distinction between press and rights with rights, you write texts or symbols of things

53
00:04:29,360 --> 00:04:39,700
that you type in, normally in a text area and press these for pressing non character keys such as down

54
00:04:39,700 --> 00:04:48,910
and to control shifts, etc. So with rights, we can write some texts such as Python is good too.

55
00:04:50,170 --> 00:04:53,250
So let's see how simple is OK?

56
00:04:53,260 --> 00:04:54,010
Do you leave this?

57
00:04:54,010 --> 00:04:59,890
Enter this empty line and go here, then run the script.

58
00:05:01,600 --> 00:05:04,630
Rides and tours and Python is good to.

59
00:05:05,770 --> 00:05:10,540
If you want to improve it also just to make a brake line here like that.

60
00:05:13,200 --> 00:05:14,370
So let me delete that again.

61
00:05:14,790 --> 00:05:15,330
Go here.

62
00:05:16,970 --> 00:05:18,470
Execute the script again.

63
00:05:21,640 --> 00:05:24,550
And so a brake line is created after that.

64
00:05:25,690 --> 00:05:34,570
So either you can press enter again or you can enter this symbol, which is a special character that's

65
00:05:34,570 --> 00:05:37,300
as a brake line, so it creates a brick line.

66
00:05:38,320 --> 00:05:43,300
Now how about if we want to copy all these text?

67
00:05:44,860 --> 00:05:48,220
So we want to select all first and then copy it.

68
00:05:48,910 --> 00:05:51,850
We do that by using the whole key method.

69
00:05:52,900 --> 00:05:59,830
So using P Oil to guide that holds key, which means this now expects a combination of keys.

70
00:06:00,100 --> 00:06:10,380
For example, if you are on windows, you do control and aid to select all the text on a Mac.

71
00:06:10,390 --> 00:06:12,730
You do command an eight.

72
00:06:13,180 --> 00:06:15,670
So two arguments divided by commas.

73
00:06:15,910 --> 00:06:20,320
And given it strings, let's see what will happen if I execute this.

74
00:06:23,090 --> 00:06:25,310
So all the tax is selected.

75
00:06:26,620 --> 00:06:31,270
But how can we compete to make it available in the clipboards?

76
00:06:32,430 --> 00:06:39,780
Again, using key, we provides the shortcut, the keyboard shortcut for copying, which is Control

77
00:06:40,770 --> 00:06:48,150
C or Command C, depending on whether you are on Windows or Mac, Linux would also be control C.

78
00:06:50,700 --> 00:06:51,090
Ron?

79
00:06:54,210 --> 00:07:00,510
Yeah, it's selected and then it's copied silently, but it's available on the clipboard.

80
00:07:00,780 --> 00:07:03,570
Now how can we access these texts?

81
00:07:03,960 --> 00:07:05,020
How can we paste it?

82
00:07:05,040 --> 00:07:12,030
Well, you can paste it using command or control v so you execute again.

83
00:07:16,420 --> 00:07:19,720
And it looks, though, as nothing happened, but.

84
00:07:20,700 --> 00:07:22,470
The copy paste actually worked.

85
00:07:23,070 --> 00:07:25,410
I'll explain you why it looks like it didn't work.

86
00:07:28,230 --> 00:07:30,390
So the chain of command source.

87
00:07:31,480 --> 00:07:33,550
Selects all copy all.

88
00:07:34,650 --> 00:07:40,560
And paced all so sudden, like it's all copy all and one paced all.

89
00:07:40,720 --> 00:07:45,750
So the moment where the text was paced, everything was selected.

90
00:07:45,750 --> 00:07:50,040
So basically the same text overall to the existing text.

91
00:07:50,970 --> 00:07:59,100
If you want to see the results, you maybe you want to praise the down arrow key ones, a then paste.

92
00:08:00,240 --> 00:08:09,780
So what I'm saying is after you select enough read copy, then perhaps say goodbye all to good press.

93
00:08:12,600 --> 00:08:18,120
Don, and then you pay so that you get out of that selection.

94
00:08:18,840 --> 00:08:20,160
So now I'll throw you again.

95
00:08:26,720 --> 00:08:26,960
Yeah.

96
00:08:27,320 --> 00:08:28,340
So, no, it worked.

97
00:08:28,970 --> 00:08:33,260
We got this text paste, it's here, so now we have more text.

98
00:08:35,909 --> 00:08:45,750
Now, if you want to apply the down key more times, you would want to make a list of how many donkeys

99
00:08:45,750 --> 00:08:47,850
you want, so two or three or four.

100
00:08:48,180 --> 00:08:51,590
But of course, we don't want to type that downstream.

101
00:08:52,200 --> 00:08:57,150
Many times you can do this, let's say five times down.

102
00:08:57,600 --> 00:09:01,350
It will give us basically, I can show you what that gives you.

103
00:09:02,490 --> 00:09:09,540
So if you say five times the list, which has only one item which is the string, don't you get a list

104
00:09:09,540 --> 00:09:14,370
of five items so run?

105
00:09:17,150 --> 00:09:18,290
Copy paste.

106
00:09:18,830 --> 00:09:19,520
You get the idea.

107
00:09:23,670 --> 00:09:32,160
In this case, it was not necessary to press a donkey five times, but I wanted to include this in case

108
00:09:32,160 --> 00:09:36,930
you want to repeat a key press multiple times.

109
00:09:37,590 --> 00:09:40,410
And this is all you can control the computer keyboard.

110
00:09:40,770 --> 00:09:43,710
Now regarding the copy paste.

111
00:09:45,410 --> 00:09:51,830
In certain cases, you might want to use the cockpit text inside Python.

112
00:09:52,610 --> 00:10:00,800
Currently, that is not possible with pilots of gum because when you copy the text, you are currently

113
00:10:00,800 --> 00:10:02,030
in this view.

114
00:10:03,140 --> 00:10:07,010
But what if you want to access that cockpit text and process?

115
00:10:07,010 --> 00:10:16,220
It's inside your Python script in here, so that's not possible, but it is possible if you use a library

116
00:10:16,220 --> 00:10:20,630
which is designed to process the text in the clipboard.

117
00:10:20,840 --> 00:10:27,290
So the text that has been copied in order to learn how to process that copy text inside the python,

118
00:10:27,410 --> 00:10:29,770
you need to take that next video.

119
00:10:30,400 --> 00:10:34,300
There are explain how to get access to that copy text within Python.

120
00:10:34,310 --> 00:10:34,790
See there.

