Placeholder Image

字幕表 動画を再生する

  • hello as programmers gets older.

  • Like most things, we begin to fall apart, particularly our wrists and our elbows and shoulders and forearms as we're manipulating the keyboard and mice to do our evil bidding.

  • S O.

  • I have tried to alleviate this problem by getting myself some economic accessories for my program.

  • The first big this anchor vertical mouse with the buttons a mounted on the site.

  • You don't have to twist my wrist to use a regular marathon surface.

  • Secondly, I got myself a logic tech G 13 left handed programmable keyboard, which, as the name suggests, it's for your left hand, and you can use your thumb to manipulate the little joystick like this on you.

  • Program the keys with whatever Mac rose on functions that you desire, and it could change all the color in coal supplies.

  • But he's also got a very nice little display.

  • Shall try and zoom in for either.

  • On this display apparently can be customized for whatever application you want to do so.

  • Typically in a game, for example, display the stats of the game, live ammo, health or in your video editing application, you can display the timeline scrubber so I wanted to see how easy was it to program this thing on Dhe.

  • I think I'm going to try and get it to display the twitch chap at the top, so it will be a similar to par video.

  • The first will be talking about how to program this on the second, but will beam or how to interact with the Twitter chat engine.

  • So I might split this video into two.

  • I don't know yet.

  • Let's see now, as I set about learning how to program the logic, that keyboard I quickly discovered that weren't really that many just getting started resources.

  • There were a few very specific applications where people had tried to customize it for a specific game on DA.

  • They were a little bit too detailed.

  • I think so.

  • This video is really going to be the very basics on.

  • The first thing you're gonna need is the A P I or the sdk and large.

  • It's extensive, and you can get that from gaming dot logitech dot com slash e n g.

  • B slash developers on for the screen.

  • The one that we're interested in is thegame panel sdk down here on gonna be downloading the 64 bit version for Windows.

  • I should know that there's a variety of SD cases, so we could if we're interested in doing things with the key manipulation we can record.

  • Macro is using the macro sdk.

  • If we wanted to change the background colors for the keys in this screen, imagine it's quite a simple one.

  • Just sending an RGB value you probably used that S D K.

  • Ah, I don't believe that the Ark's control sdk is suitable for this particular keyboard.

  • As it says.

  • It's for IAS, IOS and Android devices to displaced off some more like second screening kind of things on.

  • Of course, the keyboard is not a steering wheel, so I'm not gonna be interested in looking at those now, as usual, when I'm demonstrating a bit of software.

  • I like to use a command line example just to understand the real core of what it is I'm trying to do.

  • So I'm going to create a new project on I'm going to call it G 13 hack.

  • Why not?

  • I'm just going to go to Standard Council application next.

  • I don't want it to create anything for me, so it's an empty project.

  • And of course, the first thing we're going to need to do is add a source file on going to use the default source dot c p.

  • P.

  • There now our own like this video is not going to be a beginner's guide to how to program in c++.

  • So it is expected that you would know how to get a basic c++ program open running by yourselves.

  • That said, it isn't actually a very complicated program, a tall to get the the interaction with the law detective ice.

  • So I'm creating the most basic default template we can have for our c++ program now because we're using an external sdk.

  • First thing we're going to have to do is change some of our project properties.

  • So I've pulled that up in visual studio here.

  • Andi, we want to add an additional includes directory.

  • I'm going to stick with the debug build for everything at the moment.

  • In Win 32 when you install a C plus plus library, you are usually given.

  • Several folders include on lip.

  • Include will include all of the dot H files and liberal includes, hopefully the working compiled binary files that you'll need for your application.

  • Usually, there's some of the things in, and I will actually safer logic Tate.

  • They've not done such a bad job with getting the instructions delivered to you in a nice, clear and usable format to the instructions here in this.

  • PdF go through all of the main functions that your application will need to get talking to the keyboard, and we should see that the sdk that they've provided will work for several different keyboard models.

  • I have the G 13 here, but I believe this will also work with the G 15 because they use the same LCD display technology in both and perhaps even this one.

  • I don't think it'll work for the color LCD.

  • The documentation does appear like the intern has written it, but it is actually quite Thora.

  • I've installed my sdk from Logitech into a dry Vesti case.

  • Logitech include on I go to need to do the same for the Linka, so I go to the Link a panel, make sure you get to general and we want additional lively directories.

  • Make sure it's not include this time, but it's lip.

  • We're also going to be using one of the library files that they provide, So we'll include that, too.

  • On the name of the lip is logic Tech L C d Lib Don't lib lovely.

  • Just before I forget, they do actually provide both the 32 64 bit variants of the library.

  • So just to make sure that I'm building a 32 bit execute herbal, I'm just going to make sure it uses the right library to include the library.

  • We simply include Logitech LCD, lib dot h.

  • The compiler knows where to look to it because we've set the directory, and I just like to have a little test compiled to make sure that we've got things set up.

  • The first thing to remember about this lock detected E 13 keyboard is it doesn't really do any processing on the device itself.

  • The screen is completely passive.

  • It's my computer, which is developing basically an image file that it sends to the screen So our application will create an image file on send its using their AP I down to the device.

  • We can also use the FBI to get the status of four buttons.

  • That's all from us.

  • Not all of the keys, but just the four buttons, which are used to interact with this display for the time being, and to make things a little clearer, I'm going to enable a magic extra camera there so we can see what the displays currently well displaying one of the built in apple.

  • It's for the Logitech Tree 13 keyboard.

  • Simply displace the CPU and RAM usage valleys Onda.

  • As you press buttons, you can choose different programs, so I'm using DaVinci results for my video editing.

  • For example, I don't think I've got anything else in salt, but we don't use these buttons to work with whatever apple it is controlling the other tasks.

  • So there's nothing going on the and yes, okay, I've paid a little bit of elite dangerous recently s.

  • So there's a clock on.

  • We'll go back to.

  • So it's basically we're all tapping through the little apple.

  • It's but of course, these athletes aren't running on my G 13.

  • They are running on my computer.

  • The first thing with any drivers we need to make sure we can load the driver itself because it'll be a deal l A shared lively file and to do this in the head of file that we've been given.

  • There is a function.

  • All of these logic ones, by the way, begin with LA Gee Onda specifically lodge E L C D.

  • So we can see in the drop down list.

  • Things that are popping up for is already largely LCD in it is how will begin, and we need to give it a friendly name as you just saw it.

  • This would be where it said elite dangerous.

  • For example, it's going to display our name.

  • So I'm going to call this one the one lone Koda test that's going to the name of our little apple it, which is going to run in parallel with the other apple.

  • It's on this device on dhe.

  • I'm going to tell it that actually, it's a monochrome LCD display.

  • And let's not forget we're working with the Unicode as usual.

  • So we need to tell the compiler that our strings unico, we can do this by pre fixing with a capital L.

  • Now I'm not going to put any error checking in just a moment.

  • It's so simple, we don't really need it.

  • And so the next test that will need to do it's actually see Is the hardware plugged into the computer?

  • Remember, So far we've just looked We've just loaded the driver.

  • So to do this, we call the is connected function again.

  • We provide a flag saying, Well, have we got the mono display connected or how we got to call a display connected?

  • It seems a little counterintuitive to do it this way, because to initialize the driver in the first place, we have to tell it it's got a monotype display.

  • However, the documentation just says you can initialize it with both.

  • So, in this instance, I'm just detecting.

  • Is this display connected?

  • And I will check the response this time.

  • What's there was not really any point in calling the function.

  • So if it's not connected, we're going to split Display the message hard were not found for the remainder of this video.

  • I'm gonna assume the hardware is connected.

  • So rather than displaying that message is going to carry on.

  • Like I say, the area checking is not being included.

  • Just to keep this clear.

  • Whenever you working with new heart, where the first application you gonna create is gonna be the very birth minimum required just to make sure you've got everything settled properly.

  • So what is going to display a single word to the screen?

  • Very nicely.

  • The logical ivory provides a routine large LCD mano sent text a bit of a mouthful, which allows you to just put text on the display on.

  • There are four lines of text character text available even though it is a dot matrix display.

  • It's got some built in routines for rendering text in lines.

  • So I'm going to choose Line zero, which will be at the top.

  • And we're going to, of course, say hello World on Don't forget again that it's Unicode Now, any time you make a change to the display, you need to actually inform the driver that you want to update the display, which in this case, is the lodge E l C d o update function.

  • It doesn't take any parameters.

  • It just simply tells the driver that whatever internal image has been constructed, please download that really USB cable and displayed on the screen.

  • So just before we get started will run over what we've done.

  • We've loaded the driver here at the top and told it that there is going to be a support required for a mano device.

  • The LCD device, not the full color display that's on some of the more advanced keyboards we're going to check.

  • Is the hard work physically connected?

  • Is it plugged in?

  • We're using this command to write one line of text to the first line that's available out of the four on the display, and we're calling logy LCD Update, which will tell the driver to update the display on the hard work just to be a little bit different.

  • I'm going to run this using the deep bugger so we can see step by step that it's working on the de Booger in Visual Studio is perhaps its most powerful and best feature on Did Hold Down Control and pressed F 10 and he goes to this line so we can see the yellow line.

  • Here is the line of code that's currently executing so initialized.

  • The driver Jack is the hard work connected.

  • Well, it's not gone to this sea outline here, so it must be connected.

  • Update the text and we can see that the application is still running.

  • The CPU and RAM usage display program, but assume recall the large LCD update.

  • There we go.

  • We have displayed hello world on our keyboard on assumes our application terminates.

  • The driver has cleaned itself up on the previous apple it carries on running.

  • So we've not had to tell it to make our apple it the focus, or bring it to the front of this stack of absent of running on the device and just to give it a real workout.

  • I'm going to now get to set all four lines of text so we can see the display updating a lot more.

  • And so now call the LCD update function again.

  • And there we go.

  • Very nice.

  • The Logitech AP.

  • I also provides routines for displaying an image based on black and white pixels.

  • I'm not going to use that today.

  • As the law protect documentation is quite foreign and provides a working example of how to do this, there is one final line of code required just to make sure we really clean up everything properly.

  • And that's his large LCD shut down.

  • With this very basic program open running, we can now create a skeleton program for something a little more sophisticated you'd usually want to use this keyboard to display some sort of real time information on DA.

  • Getting that information is actually more challenging than displaying it on the screen in the first place.

  • We would typically have a little program loop here, which gathers some information about a thing, and then does all of the draw calls on the update function and it'll sit in a loop just repeatedly doing that.

  • And it's the gathering information about a thing, which is the real challenge.

  • Game developers and application developers are becoming more work off the demands of users that required modifications to the software.

  • It's the modern community.

  • That's a lot of developers now actually providing tools and a P I.

  • C u can interact with the application once it's running and get information about state, for example, in a game you might be able to get how many bullets you got left, you could simply make a query to the game that's running on your apple.

  • It or application can then use that information.

  • However it sees fit.

  • Not all games do this, and so that could be quite a challenge.

  • To get access to that information, I'm not going to go into game modeling for this video because I will be a very specific video.

  • Now the Twitch chap Back End uses Internet relay chattel IRC, which has been around for ages, and a fairly established protocol for communicating simple chat across the network on Come to think of it, this is the first time that we've done networking on the one loan coded dot com block, which means suddenly I'm gonna have to introduce sockets in a way that's understandable and friendly.

  • On Windows sockets are a bit of a mess, So the code that I'm going to use today is the burn minimum required to get a socket working.

  • So we're going to create a socket, which will talk to the twitch chats over on.

  • We'll look at the information going between the two now on Windows to get sockets working, we're going to need some more libraries.

  • In this case, we're going to need the wind sock to library.

  • Handsome structures for handling I P addresses have included the head of file.

  • We now want to go to our project properties again on Add the library as well.

  • So we go to our Linka section here, and we want to consider logic tacky, still live from before.

  • But we also want to add the wind sock to 32 dot lib.

  • And don't forget the semi colon.

  • There's no getting away from it.

  • Sockets are a bit untidy.

  • And for a council application like this, the first thing that we're going to need to do is start up the wind sock driver, just as we did with the Logitech driver.

  • I'm not going to go into the minutia of the parameters for this.

  • Lot of the documentation is available on the MST n Microsoft's own website.

  • Most of this code will not work for Linux, so the W S.

  • A startup function is used to basically load the wind sock library.

  • Then we want to create a new address.

  • So even though we know in a dress as www dot google dot com or whatever, actually it.

  • We need the ah, the I P number and we need the port number onto Luis.

  • We use an address infrastructure here, and we use the function, get address info where we can provide a literal string alternatives.

  • They get looked up on DTH e appropriate information is filled into the address infrastructure.

  • So the gets address info function here will populate this a.

  • D.

  • D.

  • Our address structure for us or it will fail on simply display to the screen Couldn't do it.

  • So if you entered an invalid U.

  • R L, for example, here it's likely to fail because it can't resolve the address.

  • The third stage of sockets is to create the sockets itself.

  • So we start by creating a socket object on.

  • We say it's a type invalid.

  • Suck it.

  • This is really just a handle to something in the operating system.

  • We will use thesaurus kit function on dhe, the individual properties off the address structure that's been populated for us to create a new socket which we've called Sock.

  • Now, the fourth stage of initializing socket is you actually need to connect to it.

  • So all we've done so far is create the socket and we've created the address.

  • Now we're going to tell it, please connect to the server.

  • This is where things get exciting.

  • Once we've created our socket, we call this connect function, which takes us sock on again takes the address information that we've created before so the address information is quite an important structure that not just contains the I P number, but also the other network settings required to create that type of connection.

  • So you can see here we've got the protocol type, what type of socket are we creating?

  • So with the most minimal of error checking, If we've not got an error, we can assume that we've quite safely connected to the server that we tried to connect to in the first place.

  • Now, like Logitech, Twitch have also released an A P I.

  • That allows you to interact with their chance.

  • So it's it's nice in this way that they're open about what's required today.

  • It's actually a very simple protocol, but in essence, the first thing we're going to need to do is authenticate ourselves with twitch register.

  • I use the name and then join a particular chat session.

  • So the first thing that we send to it is basically our password.

  • Now, clearly, I'm not going to display my twitch password on the Ethernet.

  • I'm gonna probably gonna get swatted or something if that happened.

  • So instead, I've got this nice token here.

  • Hashish, ash, some magic number from twitch.

  • If you're keen on doing something similar yourself, you'll have to register with Twitch to get a number for your application.

  • This is it's a free process.

  • It's trivial.

  • It's just clicking buttons on the website.

  • But you need to do it before you can start using any of their AP eyes.

  • And once we've created that string on notice, in this case it is a string.

  • It's not a Unico w string, because it's kind of expecting just standard asking.

  • We want to send it so we send used to send function using the socket that we've connected to.

  • We just send the string on its length.

  • We don't want to do exactly the same to register the user name, So in this case, it's going to be me.

  • This is using the nick name.

  • It's that's not really a function, but the Nick Command Jeffrey Decks nine and we do exactly the same again.

  • We send it using the socket that we've created, and finally we want to join a particular chat session.

  • Receiving information back from a socket is quite tricky because it's asynchronous.

  • We don't know when it's going to happen, so we have to program around this in a way which inevitably means we have something waiting for information to arrive so we could use signals and condition variables and clever OS principles.

  • I'm not going to do that for this.

  • And the nature of the application doesn't warrant it.

  • They received function.

  • When we use it will block my program from executing.

  • That's quite nice.

  • I don't need my program to be doing anything else off of them waiting for information from the socket.

  • So I'm going to replace our gathers information about a thing now to specifically filling a buffer using the twitch chat.

  • So the twitch server, every time somebody does a chat is going to issue some more data to all of the clients that are connected to it.

  • I'm going to need a temporary buffer.

  • They received function here, uses the socket that we've now hopefully connected to in his open again.

  • No error checking going on here.

  • Eso we used to suck it and I want to basically say please try and fill this buffer with as many bites as you can up to what a maximum off 100.

  • So I don't want a buffer overflow here assumes this receive function, reads 100 bytes.

  • It'll return.

  • It will also return in the event of failure.

  • So if the server closes the connection, it'll return a zero.

  • If there's an error, it'll return a negative number on dhe.

  • If there isn't, it will just return how many bites it could read that time.

  • So if there is only 60 bytes available, I will be 60.

  • In this case, it's quite a nice function.

  • If you developing your own programs, just display what is returned from the Twix there.

  • There's actually quite a lot of information, which is all easily possible using a string token.

  • Isar.

  • I'm just going to brute force my way through this one just to keep the code very simple.

  • Whenever twitches finish sending something it always puts on a new line or a return line character at the end so we can use that basically, to partition our commands into individual lines.

  • Remember for reading an undetermined buffer length of bites.

  • At any given time, we could be reading to commands which which are overlapping effectively in that buffer.

  • Such I'm going to create a string here, which I'm going to upend bite by bite.

  • It's not very efficient, but it's It's easy to see why this function works with a little full loop here.

  • I'm using J.

  • And if Jay's less than I remember eyes the number of bites that have been read by the receive function.

  • So basically, for each bite in the buffer, I'm going to upend it.

  • Thio strength.

  • And if the character contains the new line character, then I know that I've got a complete twitch command so I can pass that command on deal with it.

  • In fact, let's test this to see what some twitch data actually looks like.

  • Someone's going to display the character equivalent of the string every time Twitch sends a new command.

  • So I've compiled and run the program now, and we can see the messages that switches returns.

  • That welcomes me to its server has, ah, bit of a reference to a very old computer game on Dive told it that I want to join the Javid X nine chat room, which is my twitched chat room, and if active, I go there and there.

  • And so now I've pulled up sort of my twitch page here I can chat and say hello?

  • YouTube.

  • We can see straightaway.

  • Hello.

  • YouTube has been relayed back to all of the clients.

  • So it's gone through the twitch chaps server has come back to our program.

  • It is interesting to look at this line because what we can work out is that the user name that has done the talking exists between the first semi colon and exclamation mark.

  • We can also identify what the nature of the command was in this case.

  • Private message doesn't mean a message to me, but it means a message to the chat room and after the hash symbol, so we can see the name off the chatter.

  • That was me on what I said.

  • Hello, YouTube.

  • I can type in any old junk.

  • About a second later, we can see it's relayed back to us.

  • Perfect.

  • We've established working communications with the Twitch Server.

  • We just now need to do a bit of character passing to get the relevant information out of this string.

  • All the useful twitch stuff exists after the hash symbol, so we're going to find where does that hash symbol exist in our string?

  • First thing we'll do is check that it does exist.

  • If we know the hash symbol exists, we can use the sub string function to extract the remainder of the string, which is the actual chat itself.

  • So I'm going to call that chant.

  • I want to see the sub string function here.

  • I don't want the hash symbol, so I'm going to add one to the index.

  • Will hope that the hash symbol doesn't appear at the very end of the string.

  • For now, on Dhe, I'm going to display it to the council.

  • So let's launch this application.

  • So I'm bringing my Chatwin.

  • So hello.

  • And what we see now is just Javy Dex hellos.

  • This is already in a nice, perfect way to display on our logic.

  • Take keyboard.

  • I want the chat to look like it does on the screen, even though it's on the key boxes going to scroll as new items are added.

  • To do this, I'm going to need to include the list from the Standard Library because I want to be able to add stuff to the end of the list and take stuff away from the beginning.

  • So I'm going to have a list off type string and I'm going to call it s lines.

  • Now they'll only ever before things in this list on I'm going to actually populate it with four dummy objects to begin with.

  • And once we get a valid line going to pop the existing one at the front and at the back of the list and puts our new chat, which includes the username on what they're saying now, we can consider the logic that keyboard again.

  • We just want to display the four lines of text.

  • So I'm going to use a little auto here on our S lines list, and I'll use the Logitech function.

  • Margie L C D mano set text on.

  • I'm going to need to store in index.

  • I'll just create a quick temper variable called P here.

  • I want to display the string.

  • I was going to set this to P equals zero and after each one p plus plus.

  • But we've got a few areas cropping up here now, so we've only got four lines in our list on we need the index 012 and three to act our function, and we want to display the tax.

  • However, the the function provided by logic tak is expecting a double you char type character rate and not a string.

  • This is a bit fiddly.

  • A very simple and quick way to convert from a string to a W string is to use the assigned function.

  • So we take our existing string here.

  • Years iterated, zits begin and end points on.

  • We assign that so this will do the character conversion on a character by character basis.

  • It's not very efficient, but it'll do the job so hopefully then we can just pass in the wide character string Alternative W X stole us would hang on this stolen error here and suddenly This error also enhances my belief that the library and the SDK was written by the internal logic Tech is that they've not used const correctly in this case.

  • So I'm going to have to do a really dirty little work around hack to get this to work in that I'm going to cast to a W tch Artie pointer beforehand.

  • If the developer of the sdk had included constant the function, that wouldn't be a need to do this and outside don't see why they would need to be able to change the buffer that they're being sent.

  • They've just forgotten to do it.

  • I'm going to bring back on the little camera looking at the device again just to show it is live this my fingers pressing the buttons on, knocking the camera stand.

  • So if we run the application now, what we can see is the same text that we saw before I was.

  • It's just that it's mimicking the consul output.

  • So if I bring up the twitch interface again and start typing one lone Koda, we could say it's appeared on the keyboard on.

  • As we overflow the list, we can see the text girls up.

  • So we've successfully got twitch chat on the keyboard here.

  • That's good.

  • My chat is usually empty.

  • I'm not a very popular streamer, so let's try logging into somebody else's.

  • And displaying this particular popular streaming I like is Big John Game J 06 a speed runner from the speed running community on an all round nice guy.

  • What I'm going to do is, instead of joining my chat room, I'm going to join his Uh oh, something's not quite right here.

  • It would seem that all the messages are being said by the same user?

  • Well, there's a lesson to learn here.

  • Isn't that don't use your own daito in testing something.

  • It turns out that the user name of the person saying the expression in the twitch chat is the first thing that sent not the last thing.

  • Just using that hash symbol is our major passing token in string is not sufficient.

  • We need to do something a bit more complicated.

  • In fact, it's quite a little bit more complicated.

  • The user name exists between the first Cole on an exclamation mark on the chant that they're saying is after the second column.

  • So we need to change things around a little bit.

  • With that in mind, I've changed the code that extracts the text, so the first thing we're looking for is the user name, which exists between the first Cole on on the first exclamation marks.

  • I'm using sub string function to extract that.

  • Then I'm looking for what the user's saying, which is after the second colon to the end of the string if it exists.

  • So if this does exist, I then have the username and the chat out separate strings.

  • I display that the console and I also pushed them back to the back of the list.

  • Let's see if this works, hopefully be a bit better.

  • Well, there's the first message somebody's typed into his chat.

  • Onda.

  • We obviously can't display the whole screen, the whole string, so that would be required.

  • Little bit more work so we could cut off the string.

  • Depending on the maximum length of characters it can display horizontally.

  • We could see a few more chaps coming through now.

  • And if we look at Big John's chat, we can see that it's actually synchronized within the browser.

  • It's synchronized on the console, and it's also synchronized on the technical books.

  • I call that a bit of a win.

  • Looks like Big John's having to go to see him on your 64 good look.

  • So I thought it'd be fun to have a go at finding a really active chat.

  • So I found the most active chat on twitch at the moment, which is nonsense I'm interested in, and we could see that the chat is incredibly active.

  • Lots of things happening on our little keyboard is also displaying all the messages that come through.

  • I hope there's no rude once.

  • I'm not going to be censoring this on the line by line basis.

  • So there we go.

  • We've had to keep all the lodger tech g 13 and seen that.

  • It's very easy to use and in turn with we've also looked at how to log into the twixt their own how to establish very, very simple sockets.

  • And I'm saying sockets in this case because there is no error checking.

  • There is nothing.

  • Everything go up and the code is available on Gets up for the links below.

  • Uh, have fun coding.

  • I hope you can use it.

  • If you've enjoyed this video, give me a thumbs up.

  • Subscribe.

  • See you next time.

hello as programmers gets older.

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

B1 中級

Twitchのチャットを表示するためにロジクールのキーボードをプログラミングする (Programming Logitech Keyboard to Display Twitch Chat)

  • 3 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語