Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Universal Pause Button (github.com/ryanries)
501 points by RyanRies on June 9, 2015 | hide | past | favorite | 169 comments

This is nice! On OSX, processes can be paused and continued too (by name via killall, and by PID via kill):

  kill -STOP 1234
  kill -CONT 1234

  killall -STOP -c "Pandora"
  killall -CONT -c "Pandora"
A more nuanced control is to throttle down the CPU, via cputhrottle[1].

If I'm running a CPU-intensive calculation and don't want to bog down the rest of my system I will use it to give me enough cycles for Sublime Text to work smoothly.

It's easy to call:

  sudo cputhrottle PID cpuUsage%

  sudo cputhrottle 12345 400
1. http://www.willnolan.com/cputhrottle/cputhrottle.html

"This is nice! On OSX, processes can be paused and continued too"

Every once in a while I am reminded how wonderful, and perhaps unlikely, it is that I have a nice, slick, mass market consumer device (apple computer running OS X) that is honest to god UNIX underneath.

And then sad, knowing that this is a brief golden age that will probably pass.

Don't worry. Linux is slicker.

As someone who just switched to Linux from OS X, it is really hard to migrate. I miss the subtleties of the apple ecosystem. Sure Linux is awesome, but I have been battling trackpad support issues, keymapping the super_key to CMD, and just general battling the UX.

tl;dr a more powerful operating system with worse UI, which is the obvious trade. A less powerful system with a fantastic UI.

As someone who uses Linux for everything but just had to start using OS X for work, it's really hard to migrate. Remapping ctrl to cmd and various other keyboard oddities, unfamiliar mouse acceleration, and missing features like middle click to paste and holding alt to drag windows. Various other things that I'm able to customise to my liking in Linux, but are much harder to modify in OS X.

Chances are you're going to think that the thing you've been using for years is "good UI", and anything different is "bad UI". I don't doubt that Apple have spent a lot of time designing their UI/UX to work well for most people, but it feels bad to me because it's not what I'm used to.

Either way, you get used to it. I've found programs that make OS X work in a way that's more familar to me, and learned to work with the things I can't change.

UI is subjective. I get mildly annoyed whenever I use a Mac. Little things like having to click on a window to give it focus, or having to use command instead of control in many programs, break my flow. I'd probably get used to those if I only used a Mac, but since I use Linux 95% of the time and Mac 5%, I never do.

Honestly, i don't mind the window focusing on mac. What I absolutely fucking hate though, is working on Windows and not being able to scroll on a window that's not active. By default on Mac, if a window's focused, you can scroll another (unfocused) window by scrolling when you mouse is over it. Without having to refocus windows, which is really nice when you're typing something on the focused window.

As for the cmd button replacing the ctrl button. Never going back to ctrl+<key> for shortcuts. The command button is so much nicer to use, it's your thumb vs you pinky. You don't need to stretch you pinky/move you hand slightly to have access to shortcuts and that's so nice. VERY desturbing at first (I hated it), but never going back. Or maybe I've just gotten used to using my thumb. Ultimately, I think it makes a lot more sense though. No more alt-F4 to close windows, its cmd+Q, no more ctrl+B to bold a text, it's cmd+b, cmd+h minimizes/hides your window etc etc.

Also, what i found infinitely annoying at first and that I really like now on Mac, is the window switching with the keyboard. On Windows, alt+tab switches between all windows (including different instances of same program). on Mac, alt+tab switches between applications and alt+` switches between different instances of a said program. I find that more elegant when you have a lot of windows opened, which i always have.

But all these are tiny little things that add up to something really nice to use, but each individually don't and will never justify OS X being the best OS in the world blah blah. You can probably achieve a similar behavior on windows/Linux/whatever. What's nice about it though is that it's the default setup, no third party app needed/config files. You install it and it makes sense. That's why I'm not switching from OS X anytime soon, it's ergonomic, the UI is sick, power user features everywhere, and a real unix. I see it as a linux that works perfectly out of the box. I remember the first month I spent on OS X (coming from 4 years of linux, 2 yr Ubuntu and 2 yr Arch, using both full desktop env (KDE mostly) and lightweigth window managers), everything works and works well and everything is ergonomic and makes sense. Put simply, a Mac never (or very rarely) gets in the way of your work. And that makes a big difference.

But then, I just like Macs because of how I use my computer. I get it that some might prefer a Linux or Windows, and I respect that. I'm just extremely thankful OS X answers exactly what I expect from a computer.

For Windows, Katmouse alleviates some of the pain of scroll focus: http://ehiti.de/katmouse/

Wait how else do you give windows focus?

You mean like with the keyboard? Like SHIFT+TAB? That's on OS X.

I believe some window managers give the option of automatically focusing to the window under the cursor.

And once you're used to it you'll never want to go back. All of my experiences with focus-follow-mouse on commercial OSes have been almost-but-not-quite right.

> And once you're used to it you'll never want to go back.

Eh. I've used focus-follows-mouse and tend instead to strongly prefer the OS X method of allowing scroll events to percolate to the window under the cursor but retaining keyboard focus on the window it's currently in. This allows me to scroll, say, a web browser on my right-hand monitor, while continuing to type in the left.

Hover-focus is great on tiling window managers, but I'm not sure I'd react well to it where windows overlap by design.

Also, don't forget that OS X lets you scroll whatever window your mouse is over, even if it is "blurred" (not in focus). This is the one feature that I miss most whenever I need to use Windows.

There's a couple of free Windows programs that compensate for this. http://superuser.com/questions/110700/making-a-mouse-scroll-...

I, and many of the thousand or so Linux users at my company, disagree!

The only people here who really seem to like it are the ones using drawing-tablets as their main input.

Focus-follows-mouse doesn't work so great in OSX because of the global menubar, everywhere else it's great though!

It's a phase. I run into similar issues when using OSX while being used to Linux.

I went through a similar struggle when switching to a Mac about a year ago for work. I still miss the ability to drag windows around from anywhere by holding the alt key, and dragging any part of the window.

Never found a good replacement in OSX.

You can do the same non-focused window dragging in OSX by holding down command. Actually, you can interact with the unfocused window when holding down command, click buttons, etc.

Dragging overlapping windows is a stupid idea to begin with. I use a keyboard based window manager as much as possible (Spectacle), and with splitscreen I can hopefully almost completely stop using windows.

Overlapping windows is what makes mouse based interaction fast. Not everybody wants to use keyboard all the time. Also, often times it is useful to have more than two windows on screen at a time.

> Overlapping windows is what makes mouse based interaction fast.

How does the overlappingness make anything faster? If anything it becomes slower, because you need to move windows out of the way, or select them before you can get to the covered part.

> Not everybody wants to use keyboard all the time

In no way necessary. I don't think the WWDC splitscreen demo used keyboard shortcuts at all?

> it is useful to have more than two windows on screen at a time.

Having more than one window on the screen is also not helped by the windows overlapping. I regularly have 2-4 windows side-by-side on the same screen at once without overlapping, and multiple such screens and fullscreen windows on virtual desktops.

I use HyperDock for this: http://hyperdock.bahoom.com/

It's mainly focused on modifications for the OS X dock which I don't use, but it also does alt drag window movement, and alt + num pad for tiling windows. It costs a a bit of money after a trial period, but it's the most reliable replacement for alt drag I've found so far.

haha. You guys must be right. That is the exact functionality that is the most annoying for me right now! I need to get used to this new OS. I miss 3 finger swipe right. ctrl+alt+shift+ [direction] is quite a macro just to move a screen.

I personally changed that to be Super+<Arrow> to change virtual desktop, and Super+Shift+<Arrow> to move the focused window to it. Much nicer shortcut, IMO. Elementary OS[0] uses that by default, actually.

[0] https://elementary.io/

Realize that what you mean with "to get used to this new OS" is possibly "I need to get used to this desktop environment / window manager". I don't know what desktop environment you use but it is possibly Ubuntu's Unity, Gnome or KDE.

On Unix you have a lot of choice on the (graphical) interface you chose to interact with. So while to one you're currently using might be OK, there's bound to be one that's even better suited to your needs.



(Also, it's usually trivial to change your keybindings.)

yep thanks. I run ParrotOS which is basically debian with some slick UI and pentesting toolsets. It is a gnome desktop enviro. I will check those links out. The keybindings did not hold on the tut I followed, no biggie. My major point is that I am a mac superuser, but when I switch windows I have to manually deselect a window (because it follows me). It is just absorbing the nuances of linux and inculcating the macros into my head.

It is like switching from JS to Ruby for me.

Linux is a lot of good things, but "slicker than OS X" (in the sense of basic user-friendliness to the average computer user) is not really one of them.

Don't say that... why would Apple change the underlyings of OS X? Blasphemy :(

The precedent is already set. iOS is underlain by the same components, but the end user has no access.

We have also seen an incremental approach in the gradual replacement of open APIs/components with closed ones.

They will when it conflicts with their business model. Witness protected access to media keys and the Notification Center.

Many would argue the golden age of OS X and nix compatibility has already passed. The last time I seriously used OS X was 10.4, but every release I hear about another set of nix compatibilities getting chipped away.

Could you give some examples please?

> New operating systems today tend to be just ways of reimplementing Unix. If they have a novel architecture -- and some do -- the first thing to build is the Unix emulation layer.

> How can operating systems research be relevant when the resulting operating systems are all indistinguishable?

> There was a claim in the late 1970s and early 1980s that Unix had killed operating systems research because no one would try anything else. At the time, I didn’t believe it. Today, I grudgingly accept that the claim may be true (Microsoft notwithstanding).

> A victim of its own success: portability led to ubiquity. That meant architecture didn’t matter, so now there’s only one. Linux is the hot new thing... but it’s just another Unix.


Here is a quick clone of this project for Linux using the STOP and CONT signals:

  currentProcess=$(xprop -id $(xprop -root | grep -F '_NET_ACTIVE_WINDOW(WINDOW)' | awk '{print $5}') | grep -F '_NET_WM_PID(CARDINAL)' | awk '{print $3}')
  state=$(grep 'State:' /proc/$currentProcess/status | awk '{print $2}')
  if [[ "$state" == "T" ]]
      kill -CONT $currentProcess
      kill -STOP $currentProcess

SIGSTOP and SIGCONT are generic Unix signals.

Where it gets more interesting is using elaborate checkpoint/restore [1] mechanisms for processes to serialize their state (open fds, watches, IPC, etc.) into an image that can then be overlayed, remotely executed, debugged and so forth.

[1] https://en.wikipedia.org/wiki/Application_checkpointing

I've always thought this was a wrongheaded solution.

I mean, of course, we have these apps that splay themselves all over global system resources in complex ways, and so we need to track down how they've done that, record it, and then replay it later to restore them. It's necessary.

But imagine a well-behaved classical X11 app, running in something like a VM or Docker container. You execute its launcher, the VM spins up in the background, the app launches in the VM, and the app's X11 client connects to the X11 server you're staring at and displays things.

If we truly want to sandbox apps, wouldn't it make more sense to move more toward a model like that—one where you have a discrete "application backend process" running in a sandbox, and you can just chuck around the sandbox itself willy-nilly (freezing it, thawing it, copying it, etc.) because it has well-defined connection-points to the host?

The purpose of C/R isn't sandboxing, it has nothing to do with it. It's about managing internal state and data structures from an external agent.

C/R enables complete persistence by duplicating a process from its image, which can cut initialization and startup times by orders of magnitude, and resume service from an exact position with zero downtime, and not just basic mechanisms like socket superservers.

It lets you back up process state at any arbitrary moment, send it over the network, recalculate and reexec immediately and then thaw again for debugging it from that particular point.

It just helps enable live migrations and zero downtime recoordinations with far less complicated redundancy schemes. This includes containers. On top of it being a universal save/pause button.

Depending on the robustness of the image format, it can be made space efficient through deduplication.

C/R is quite invaluable for any scenario that involves fault tolerance, high response times, tracking down difficult bugs, low startup overhead and so on. I'm surprised why it's still such an obscure technique.

Besides, I don't think the primary use case here is even graphical apps (not that they don't work just fine). What you really want is a local indexed copy of all the execution environment details, like pipes, sockets, timers, ttys, timers, sigmasks, *fds, etc. for infrastructure.

OK, PowerShell magic time:

  $a = Get-Process calc
  $a.ProcessorAffinity = 1
  $a.PriorityClass = "Idle"
  $b = [Diagnostics.Process]::Start("PowerShell", "-c while (1) {}")
  $b.ProcessorAffinity = 1

I actually wrote a little GUI app to do this for me a while back! It works but the UI is a bit broken. Maybe somebody will find it useful.


On debian the program is cpulimit.

I think using nice or renice is better practice. Hard throttling is way more inefficient.

It may be, but it doesn't solve some of the problems that cputhrottle does. My main use for cputhrottle is to limit the CPU usage of Flash. It's not that I want to use the CPU for something else, at least not at the moment, but I don't want my laptop's fans to turn on, the whole thing to heat up and it to kill my battery life. [re]nice will only allow another process to get CPU priority, it won't keep the CPU utilization low.

The bizarre part, when it comes to Flash, is that I've yet to see an actual difference in the application behavior when I throttle down it's CPU usage. I would think that if it normally maxes out 7 of my 8 logical cores, being limited to 40% of one core would make introduce slowness. But I guess that's just an indication of how poorly written the OS X flash client it.

You might not notice the difference, but that guy at Apple who's only getting 5% of his usual haul of bitcoins this month sure will!

Flash is running an event engine like JS under there. Your comment made it occur to me that they might busywait, rather than having a proper scheduler. This seems insanely lazy.

It's not a busywait, they use the extra CPU to render additional animation frames. But half the time the difference is not visible anyway.

Only yesterday I was raging at Flash for continually chewing up my CPU and RAM. I hadn't even considered setting limits on the processes. So thank you for the suggestion.

Nice solves a different problem: Making sure that less important programs don't hog cpu time.

I use cpulimit to force a CPU bound program to slow down. I also use it for programs that always max out the CPU for no good reason, and work fine with less CPU.

Nice won't help with either of those.

The kill -STOP command works on linux too

It does, but cpulimit repeatedly stops/continues the program to keep it within a certain amount of CPU.

It works pretty good, but I have had flash games crash if you limit them too low for a while.

Ok I had a total brain-fart there.. I didn't realize that you were responding about the cputhrottle command. Whoops

Great app but I have one request. Can you please modify it so instead of pausing the game until my SO is done talking, it pauses my SO until my game is done its cutscene? Thanks in advance.

Ah, I didn't know Adam Sandler posted on Hacker News.

Try this: http://placebobutton.com/ It was featured on HN recently.

This should be a basic requirement for all games. Even before I was married my mom would call or someone would ring the doorbell. And when I was a kid I had to go down to dinner or take out the trash.

"Tricks of the Mac Game Programming Gurus [http://www.amazon.com/Tricks-Mac-Game-Programming-Gurus/dp/1... actually dedicated about a paragraph or two to the topic, driving home the point that a game that cannot be paused is leaving N% of potential players on the table right out of the starting gate (and I believe they even had a hypothetical about "little Jimmy" not being able to pause to take out the trash and therefore his parents uninstall the game).

These days of MMOs and other coordinated time-sinks make me miss the simplicity of pausable single-player and turn-based multiplayer sometimes.

That is probably 90% of the reason I stopped playing multiplayer games. Which sucks because the number of single player games I want to play is, I feel, getting smaller over the years. There was a day when first person shooters, no matter how good the multiplayer was, had a single player campaign as well. There was a day (even when processors were absolute shit) when you could add bots into the game and they would play like humans with personalities.

Hell, even the single player games are getting to be unpausable. How many cut scenes are there in GTAV? And if other duties are at hand, the only option is to skip the story line so you can pause.

One problem with real-time multiplayer games is also the sensitivity to latency. It can very easily be impossible to play any game that is sensitive to latency together with people from several continents. I'd wish there'd be more games that don't rely on fast connections. CIV 5 is good exception, with it's well though-out multiplayer modes.

That reminds me of the old "Supervisor Key" in classic early games.

Yeah! Like the boss key in Leisure Suit Larry: http://www.mobygames.com/game/leisure-suit-larry-goes-lookin... Now THAT is a job ad ;-)

"Oh yeah, I was just working on this spreadsheet." Those were the days...

Years ago, I wondered why hypervisor-level pause (and memory snapshots, for that matter) weren't just expected features for game consoles.

These days I can at least hit the Home button on a Wii U game and expect it to work. Emulators are still hogging save-states all to themselves, though.

It's why I love the Nintendo DS and its successor the 3DS - any game can be paused just by closing the lid! In this low-power mode it can last for many hours, possibly days.

Absolutely days, I close mine and reopen it a week or so later. I never actually turn it off.

I'm still having nightmares of someone interrupting me during those long and unpausable metal gear solid cutscenes

MGS 4 is like 50% cutscenes. You can pause them though - thank fuck, the ending cutscenes are over an hour in length or however long it was.

Yes, the ending cutscene after you beat the game is one hour and eight minutes long. Source (sorry it's an infographic): http://venturebeat.com/2012/04/17/infographic-metal-gear-sol...

Great idea, will be helpful.

Now, I only need a similar tool that kills the process with the highest CPU and MEMORY load with a short cut. Reasons: Sometimes a process leaks memory and fills up 16GB RAM and opening a new process like taskmgr is impossible to severe paging-IO. Sometimes a full screen application crash and spawns a modal crash dialog behind the full screen window so only taskmgr and keyboard usage works (as the mouse is hidden by the crashed full screen app).

Magic SysRq-F

Wooow, thanks a lot! I'm going to test it now.

Edit: Not working as expected :(

Run python script that allocated a couple of gigabytes of RAM effectively causing my machine to freeze. And OOM killer figured out the best thing it can do is this:

  [2889118.406439] Out of memory: Kill process 11878 (SpotifyHelper) score 302 or sacrifice child
  [2889118.406442] Killed process 11878 (SpotifyHelper)

Such are the ways of the OOM killer: http://lwn.net/Articles/104185/

If it's a specific program that's doing this, maybe you can wrap it with a script that executes ulimit.

You can also download the executable (if you don't want to compile it) from https://www.myotherpcisacloud.com/post/universal-pause-butto...

You should consider uploading that file to the Github repo in the "Releases" section so people can find it easier.

Good idea.

You should not pause explorer.exe

Agreed. Learned that the hard way. I have since updated the app with an exclusion specifically for explorer.exe. Later I'll scan the registry and find what the user's shell is, just to cover the rare case that the user has a custom shell.

Really cool. Well done!

Did you try it on Wine yet?

Wine? What about SIGSTOP?

"I've already gotten great value out of the program, as there are lots of cut scenes in The Witcher 3, that I don't want to skip."

The Witcher 3 pauses cutscenes when the window is not in focus. So the example is probably not the greatest.

My son has been playing Witcher 3 for the last few weeks, and literally every time I walk by, there's a cutscene. I'm pretty sure I have yet to see anything but cutscenes. It's all cutscenes. Listening to it in the background, it sounds more like an episode of Sons of Anarchy than a traditional videogame.

The script is apparently ~450,000 words! I have 28 hours of playtime but the game only shows me at 17% completion - its massive and detailed open world is stunning.

450 kwords? That's like 2-3 large novels...

1984 was around 85,000 words (from memory). So 5 times that

Wolfram Alpha says average word length in English is 5.1 chars.

450000 words * 5.1 bytes ≈ 2.2 MiB

I like to read novels on my phone in plaintext format. 2001 by Clarke is 368 kiB. Red Mars by Kim Stanley Robinson is 1.1 MiB.

1984 would be 423 kiB, which I consider pretty normal, not "large". But that's subjective, I guess.

So then every time his wife walks in to ask a question, he immediately Alt-Tabs to another window, and she thinks he's watching porn all the time.

Well, I run fullscreen windowed, so something on one of my other two screens just take the focus. The game is still visible and is just paused.

I can confirm this as well. If you simply switch to another window or application, away from the game, it'll pause the cutscene.

Nice idea and app. Having a quick look at the code I had forgotten how much work needed to be done for old-skool Windows applications. They do give you great lean applications though which is something I miss.

I will always have a soft spot for small, lean single function applications. I guess it takes me back to my UNIX days. Some of my favourite more modern programs are SumatraPDF, uTorrent (the older 2.x versions) and Notepad2, lovely single exe programs that are self-contained. No installers and messy configs all over the place or in the registry.

Sumatra PDF is the best. I actually prefer it, running under wine, to any of the Linux PDF readers I've tried. I used I to write/preview my thesis.

Did you try Foxit reader? They actually have a Linux build that is not as feature-full as other releases, but still better than any native Linux PDF reader.

Transmission is a great replacement for uTorrent IMHO

You can do this to any process in Windows' Resource Monitor too - the one you can open from task manager. On the CPU tab you can right click any process and suspend it.

not seeing this in Windows 7. Is this specific to Windows 8 and above?

From Task Manager, open Resource Monitor. That's the one with green charts on the right hand side. It has different context menu than the Task Manager. Picture (on windows 8): http://thewindowsclub.thewindowsclubco.netdna-cdn.com/wp-con... I'm not sure if Windows 7 has it, though.

Win7 has it. In task manager, go to the Performance tab, and then press the "Resource Monitor" button.

Or run `perfmon /res`.

That's interesting. However, I wonder ... don't you think it can be abused in some games that try to compensate lag? For example, what if they use a code similar to:

  delay = currentFrameTime - lastFrameTime
  playerPosition += direction * delay
I know that some games (such as Diablo III) may automaticallt ban you if you happen to run a program that may be used to cheat (they detect that via a background process check).

I have thought about this. In fact I even asked Gabe Newell about whether the use of this program might falsely trigger some anti-cheat mechanism within Steam. (He hasn't replied yet.) So, I guess until I get more official information, please proceed with caution and use at your own risk. That being said, that would imply that using Process Explorer or PsSuspend could also get you banned, since those applications also have the ability to suspend threads.

Yeah do be very careful with this, many anti-cheat programs are very trigger-happy.

Some time ago I had an application crash on a development machine while I was playing a game. On my dev machine crashes go straight to ollydbg. Next thing I know I'm kicked from the game, and it tells me to stop 'using cheat programs'. Go figure :p

Heh, spotify did this too, if you had any debugger running then it would just instantly shut down. It probably still does it.

He wrote it's useful for singleplay games that have an intro. If you use it in multiplayer games you certainly will simply drop out of the game as you will loose the connection or what you described depending on the server implementation.

A popular multiplayer cheat is to suspend the network stack somehow for a split second while their team gets into place and resume causing the game's network code to resync and players will teleport into advantageous positions or become extremely difficult to target or hit during key moments. It's very hard to detect especially if the program doing the suspending is on the router and not the system running the actual game.

Example of this in action: https://youtu.be/I5QyNA6H6rY

Sure, the issue is that even if you don't use it, the simple fact that it is running in the tray may be enough for an anti-cheat to trigger. Just something to keep in mind.

That doesn't just apply to multiplayer, though. OP said Diablo 3, which is multi OR single player. Many games now use those phone-home anti-cheating measures (or drm measures) even when you aren't actually playing with anyone else.

Diablo 3 is an always-online game; the reason is that you can take the items you earn in single player and use them for your multiplayer character (and vice-versa). Their security is extra tight because up until recently, said items could be traded for real money. And you don't want anyone to be able to generate things like that offline.

Although they did, there were some item duplication bugs. And even that was irrelevant, since there were quickly popping up small armies of item / gold farmers; every once in a while they'd get banned, but by then they would've earned enough money to buy another fifty copies of the game and continue.

Is Diablo III single player? When I played it at the release, connecting to a remote server was required (which is a shame, btw. I will miss the modding community that Diablo II had).

It can be single-player, but you still need a connection to do so.

Is this also true for the console port(s)?

It is multiplayer only (always connected) but you can play it alone.

It could be considered an exploit in games like Dark Souls where other players can invade. Just pause the game for a few seconds and their connection will drop.

Now if only there was a Universal Skip Button for those games with unskippable credits, intros or cutscenes!

One can usually just rename/delete the intro videos (*.bik) or replace them with 1s bik video file or add a commandline flag to the desktop link or a setting in the config text file. But, an universal fixing app that has some heuristics would be more convenient.

This actually is sort of possible, you have to mess with the system clock as seen by the program, to make it think much more time has passed than really passed. It will run those scenes at hyperspeed.

Then give back the time later (if you need the clock to match the real clock) when it's waiting for input.

There was a program called cheat engine that let you drag a slider for program speed, as well as generally dig around RAM.

If there is, PCGamingWiki will generally have it.

e.g http://pcgamingwiki.com/wiki/Remember_Me#Skip_intro_videos

Indeed some deep nesting here. You made me remember a quickbasic program I wrote for a class back in early 90s, where I packed the whole program in a single do-loop with about 20 indent levels at it's deepest, and I loved it. But... the prof told me to never do that again :( Anyway, thanks a lot for the flashback :)

Deep nesting always bugs me too. It's so much cleaner and easier to understand (for me anyway) to identify the else case ahead of time and stop processing immediately.

Agreed, it's not the most elegant code, but it's so short and simple I haven't bothered reorganizing the code yet. I probably will start adding features like re-bindable pause key, etc., and I will untangle the mess a bit at that time.

quickest way to do it is to negate your if conditions in the loop something like this:

    if (ForegroundWindow)
        MessageBox(NULL, L"Unable to detect foreground window!", L"UniversalPauseButton Error", MB_OK | MB_ICONERROR);

    if (!ForegroundWindow)
        MessageBox(NULL, L"Unable to detect foreground window!", L"UniversalPauseButton Error", MB_OK | MB_ICONERROR);

I've added a pull request which reduces nesting a bit: https://github.com/ryanries/UniversalPauseButton/pull/2

Alright, should be pretty much taken care of in version 1.0.1.

Without reading the explanation, immediately my roommate and I figure out how to do it via the linux terminal by pausing the main thread. It seems so obvious, don't know why I wasn't doing this myself.... since I have the same problem as the OP.


I've added this to the scoop-extras bucket for Scoop[0]. So users with the extras bucket can install it using:

  scoop install universalpausebutton
EDIT: Do you have a licence?

[0]: http://scoop.sh

Thank you! Added MIT license.

Really clever. What a thoughtful project, too. Hope your SO appreciates the work you put in on it!

Wow, coded like a simple old school Win32 API win app, I didn't realize that was still possible in modern Visual Bloatio. Nicely done.

My favorite kind of application. Small, lean, close to the metal, and built like a brick house. :)

I love this!!! The pause button was incredibly useful when trying to figure out what went wrong with DOS boot sequence. I wonder if it would be possible to include support for it in Linux kernel? Sometimes I would like to read those messages that fly over the screen (no, dmesg is not enough)...

This program doesn't pause the kernel, just the game's process. Other people in this thread have given equivalent solutions for un*x.

If you want to actually pause the linux kernel you'll have to use something like the magic SysRq: https://en.wikipedia.org/wiki/Magic_SysRq_key

Alternatively you can run the operating system in an emulator like qemu.

Why isn't dmesg (combined with syslog to catch messages from daemon startup) enough? I've dramatically increased the size of the kernel ring buffer (so it -in practice- doesn't evict any message) and done ...something... -I can't remember what- to push early dmesg output into syslog.

This specific example is nice although not truly universal.

An interesting startup idea would be a bluetooth thingy (kinda vague, maybe a necklace?) that when pushed becomes a TRUE universal pause button. Pauses my DVR, my car audio, my linux mythtv box, everything, silences my phone ringer, mutes the TV, shuts off the alarm clock, temp-mutes the smoke alarm if its currently going off, silence the oven timer, car alarm off if its currently sounding, you name it.

Sounds technologically possible although a huge PITA, which sounds like a great startup idea.

You might need to ram thru a whole new bluetooth LE broadcast protocol, maybe. Or just a blind beacon of "anything" thats sniffable (edited: whoops that wouldn't work so well with silenced burglar alarm systems).

I suspect this would sell pretty well once it gets universal...

years and years ago I had some thoughts tumbling around about how I'd design an automated system for muting/vibrate-mode only for phones in cinemas/libraries/quiet-zones, etc.

The security implications and UX involved in managing settings in a non-infuriating fashion rapidly sunk it though, and I daresay it would never have been practically deployable unless business/landowners/whatever could enforce its use as a condition of entry.

Also, you forgot the hollow tooth + airbag components + RF magic => remote operated ball-gag :P

Win10Phone/Android/iOS apps are suspended and restored the same ways too. Only the visible app (and some system processes) is running in iOS1-8 (in iOS9 iPadAir2 two apps). It's usually unused in desktop OS (except for universal apps in Win10).

I would love this for Mac, not for games but for all browser tabs. Find whichever tab I'm playing music in, and pause it, whether it be SoundCloud, YouTube, or some other streaming something. Fantastic idea though!

At WWDC, they announced that the new Safari version would be able to do something like that.

That's only muting tabs, which Chrome has been doing for years.

Always used to watch those cutscenes on youtube! Awesome app btw.

Having a modernized pause/break key on your keyboard can also be handy if you ever have to use software that acts stupid on purpose, like these "Safe Exam LockDown Browsers" that some schools and universities around here have started forcing upon their students. Software like this typically just run a timer or similar to make sure that only their windows are running in the foreground, but sending them a SIGSTOP stops this annoyance.

But what if the process uses a timer to update an animation? (I.e., the state of the timer determines the frame in the animation).

In that case, after unpausing, the animation would just skip ahead.

As a remedy, the pause button could also stop the system clock as seen by the process.

Yep, different applications are guaranteed to react differently to this, depending on how they were written. And a lot of games use the _rdtsc intrinsic straight from the CPU... I can't pause that. :)

You could write a virtual machine that compiles all code into essentially the same code except for the rdtsc instruction (basic-block analysis).

That is a lot of work, but I wonder if there are no debugging or reverse-engineering tools that work in that way.

Wouldn't it be easier if your girlfriend would not expect that she can walk in and interrupt you any time she wants?

Well, maybe. But then maybe I wouldn't have a girlfriend. And more importantly, maybe I wouldn't be reminded that sometimes it's OK to peel myself away from a video game.

Reminds me of old utility which could resize any DirectX based game and force them run in windowed mode.

For a fraction of a second, part of me really hoped it could somehow be a pause button for life itself.

Would love to have this for email.

aka "Windows users discover our CTRL+Z" :) Been doing that very often during Ludum Dare where the best games have usually very fine gameplay and very poor everything else, like lack of pause or progress save - surely came handy.

On OSX you can use Activity Monitor to use View > Send Signal To Process....

It even pauses video studio! It really is universal.

Damn, I thought this was for real life.. could've used one of those. Better than hitting snooze 10 times.

It wasn't until MGS4 before the Metal Gear Solid franchise got cutscenes which you could pause. Which was sorely needed because of how story driven the series is, and how long some of the cutscenes are -- I think the end of MGS4 was something like 1 hour, 30 min.

Can we pause the significant other too?

"I like to play video games. I also have a significant other, and she often walks into the room to talk to me while I'm playing a video game."

Looks like the real solution would be to pause your SO ;)

I encountered this problem with babies. They definitely don't pause.

My solution was the DS/3DS line of consoles... snap 'em shut, bam, paused. I've called them the consoles of choice for the discriminating father.

(If you've never had kids and find yourself wondering what horrible father would be playing video games while taking care of his children, well, you see, it turns out that sometimes your child wants to sleep on somebody, and will not sleep any other way... and there's only so many things you can do with a baby that cries if you move sleeping on you. Both of my kids went through that phase for different reasons.)

I was able to bottle feed my daughter when she woke up at night and simultaneous play through and finish Braid over the course of a few days/weeks. Through some sort of weird pavlovian conditioning I started looking forward to her waking up in the middle of the night (I restricted my playing to night-time feedings to give myself something to do during those times).

> My solution was the DS/3DS line of consoles... snap 'em shut, bam, paused.

I'm a fan of this as well - works for PSP and Vita too, just quickly press power and it's in sleep mode. However, I have run into one game that didn't properly pause itself when closed. I think it was Kingdom Hearts 358/2 Days. Its cutscenes didn't pause when I closed my DS. Otherwise, yeah, this is the greatest.

Does the Xbox One not do this? I mean suspend gameplay and resume with just a touch of a button?

I believe the PS4 does this too.

It does.

"Universal Pause Button" my eye, I tried it and the universe just kept going.

No, it worked - you were just paused along with it. (It times out automatically if there is no user input.)

you have to focus the right window, can you do that?

uh and you'd need to find that pause key the dimension above...

test comment!!

Applications are open for YC Winter 2024

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact