 I wanna talk about a universal way to bind keys in every Linux graphical environment, totally independent of your window manager, your desktop environment. Now, if you watch my channel, you might know that me and a lot of the people who watch it, you usually use tiling window managers. Tiling window managers, the one I traditionally have used is I3, they have the ability to bind keys to different commands or scripts or other kind of things. And that's something that I've gotten very used to and a lot of other people rely on all the time. But I've been playing with other window managers now, and if I define all my keys in I3, when I move to another one, they're all gonna be gone. And there are some that I want in common. I want my media keys, my keys for going to the next music track or changing volume or a lot of my function keys or a lot of just the keys that open programs. I want them all to be pretty much the same. On any window manager I hypothetically use, if I use GNOME or XFCE or something like that. So in this video I wanna talk about two programs that are very nice if you want a modular setup where you have the ability to take your binds and put them wherever without having to worry about them. I'm gonna talk about two programs that do this. And I wanna talk about two programs just because they're basically the same 99% of the time. But then you could choose which one you like more. There's a more traditional alternative. And that is X bind keys. And again, X bind keys, you can have it run in any environment and it will map keys to whatever you want. And the other program, this is a little more, I guess popular nowadays is, what is it? Simple X hotkey daemon, SXHKD. One of those things where the acronym is much harder to pronounce than the actual thing it stands for. But this one has a little bit more features. It was actually written, I think I pulled up the GitHub for it. I think it was written for like BSPWM, whatever it is, which doesn't actually have any kind of key binding system whatsoever. So it is supposed to be very modular. And it actually, both of these have features that most of your window managers might not actually have. And especially the Simple X hotkey daemon. It has some really cool stuff and I'll talk about those. But again, so just to be clear, how to, before I show you what these config files look like and how to set up key bindings, if you want them to actually run, you have to have the program installed. I have both of these installed, but I'm using Simple X hotkey daemon now. And you want to put in either your X in it or C. You wanna put, just run the command like this and that'll be about it. Or if you use a graphical log in, you wanna put it in what is it, X profile or whatever. So you can do that in either case, X profile, just to write it out so people know what it is, I guess. All right, so let me show you what these actually look like. I'll open up both of these because they're pretty similar. And now X bind keys, its config files in the home directory. And I will also open up the config file for SXHK, whatever, the other one, Simple X hotkey daemon. Do I already have this open? Whatever, I probably just left it or something. Anyway, this is what they both look like. Let's look at the X bind keys config. Again, it's the more traditional choice, I guess. And again, you'll see some similarities between the two. So the X bind keys file, it looks like this. You put a command, you wanna bind in quotation marks. And then on the next line, you put whatever you want that bound to. So in this case, ST, my terminal is bound to mod four, which is the super key plus return. Or D menu run, which is my command prompt is mod four, which is the super key, the windows key plus D. So I have a bunch of programs mapped here. I have a bunch of personal scripts here, for example, D menu Unicode. If I wanna copy a Unicode character or something like that, I have a bunch of my scripts that I use just all over the place. If I wanna shut down the computer. And again, these are gonna run on any kind of desktop environment. I also have music control and other stuff. There are things, of course, I don't have in here. And those are binds that are specific to each window manager. I bind those in the window manager itself. But one of the reasons I wanted to move to the, I've been configuring DWM, as you may notice, I'm in DWM right now. But to add bindings, you have to create a function in DWM and add it to this array and recompile it. It's a big pain. I just found this a little bit easier, especially considering it will bind them for any graphical environment. So here are the bad things about X bind keys. Most of the time it's gonna work. But there are a couple commands where it gets a little confused. If you have quotation marks, obviously, since these commands are going in quotation marks, you're gonna have some trouble where you have commands that have quotation marks. Because you can't really escape them in the way you expect. Now, I think this works. This command actually doesn't work. I think it's because it has a pipe. I'm not exactly sure. But either way, I didn't really debug it because the simplex hotkey daemon does it all better. Now, one of the things, I'll go ahead and start talking about the simplex hotkey daemon, which looks pretty similar, except for in this case, they have you put the key you bind first and then the command you bind it to. But a couple advantages that the simplex hotkey daemon has. First off, you can use shell variables. So I can say terminal and it's gonna read that variable that I assigned to my desired terminal. You'll notice that back here, I had to manually put my terminal name ST in every position. And of course, you really want it to read shell variables because I'll probably in the future, well, no, I won't probably change my terminal. But hypothetically, if I wanted to, I could easily just change my variable and not have to change this file at all these different lines. But otherwise, it looks pretty much the same. And since you don't have like quotation marks, you don't have to worry about it messing things up like this command or something like that that has quotation marks. You don't have to rewrite anything. And I mentioned there was that other command that had broken the graph command, which works totally fine in the simplex hotkey daemon. In addition to this, so the hotkey daemon actually has some other features that work are really convenient. So one of them, I think I is up here. So one nice thing is, if you have like separate lines for all these bindings, it's gonna be a little bit annoying. So one nice thing that the simplex hotkey daemon has is that it has this tercer way of binding multiple keys per line. So for example, I have a command LMC, which is just a wrapper. It's like a music controller. And LMC next means go to the next track. LMC previous means go to the previous track. And I map these at the same time to super plus greater and super plus less with this kind of syntax, which is specific to the simplex hotkey daemon. And this basically means if I press super and greater, it's gonna run LMC next. If I run super or super plus less, it's gonna run LMC previous. So that's a very nice way. And you can see you can do other things with this. Like for example, this, you know, let's see. Over here, I have super and super without any kind of other modifier compared to super plus shift plus P. So it's pretty convenient, the kind of things you can do and you can play around with it. Another thing that both of these, actually, let me think about this. One of these things, I don't actually have it in my config file, but it's really sweet. I sort of want to think of ways to start using this, but if you can check the documentation for it. What you can also do in the simplex hotkey daemon is that you can have, you can bind sequences of keys, which a lot of window managers, like they don't really have the ability to do, but they give an example here, and I've tried this out, it works pretty much exactly how you'd expect. So in this case, what you do is super, if you type in super O and then follow, you can follow it with another key, with E, with W, with M. And super O, E will open up GVM, or super O, W will open up Firefox, or super O, M will open up Thunderbird. I haven't put any of these in my config file yet, but it's one of those ideas that's pretty cool. I'll probably implement it pretty soon once I decide how to organize all the rest of my keys. So that's a really nice ability to have. Additionally, I haven't actually gotten it working, but allegedly both of these programs, both X bind keys and the simple X hot key daemon, have the ability to map release events. That is when you release a key. Maybe it's my keyboard problem, I'm not exactly sure, but I haven't quite gotten it to work. But how you would do it is, I think they give an example here as well, you put a little at sign. Yeah, so this here would run when this button here is released, because it has an at sign before it. It doesn't really work on my machine. Maybe I don't understand how they intend for it to work, but it just runs like a little bit after when you first press down. It might be my own personal problem, I don't know. But you can do the same thing in X bind keys by specifying, you can say like, release and that'll work how you'd expect. So that's another cool thing. So just generally, I definitely recommend you checking out these programs because it's nice to have a more modular setup. It's nice to be able to, I find this a little bit more of a readable file than like sending people my i3 config, which has a bunch of junk in it. Definitely more than a DWM source code or something like that. So I definitely recommend you checking this out. Again, to run it, you just throw it in your X init RC or your X profile. Either you can, the X bind keys command, I think it's just X bind keys. So X bind keys. So that's how you would do it. And one other thing, I don't think I mentioned this before, but because I'm lazy, I'm super lazy, I actually put everything in VIM. So whenever I save one of these config files, as you can see, as you can see here, I have VIM automatically kill the previous instance of the hotkey daemon and rerun it so it has the new settings. So that way, anytime I edit these files, I don't have to restart my window manager. I don't even have to run a command. It just automatically updates. And that's nice if I need a troubleshoot. That's nice if it's just nice, it's convenient. So anyway, so hopefully that'll give you some ideas for kind of things you can do. Actually, let me give myself five seconds. There might be something else I forgot about that's really cool that I want to show. I think that's about it. But anyway, if you know anything more about these programs, feel free to throw them in the description because I've only been using them a couple of days. But either way, that's about it for this video and I'll see you guys next time.