← Back to Blog
•8 min read•
SaaSNext.jsReactTypeScript
Xolito: I built a VS Code extension that hides your screen when your boss walks by
As a SaaS developer, you know how challenging it can be to stay focused while working on a project. DiggaByte's platform helps you configure your exact tech stack and instantly download a production-ready ZIP, but even with the right tools, staying productive can be a challenge. In this article, we'll explore a simple yet effective productivity hack that shields your screen from prying eyes in real-time using Node.js.
Imagine being able to switch between a "focused" and "distracted" mode with just one click. This productivity hack is not only useful for developers working on projects, but also for anyone who needs to work in a shared workspace or collaborate with colleagues.
Setting Up the Productivity Hack
To set up this productivity hack, we'll use a simple Node.js script that listens for keyboard events. When the user presses a specific key combination, the script will automatically switch between the two modes. #### Step 1: Create a New Node.js Project Create a new Node.js project using your favorite IDE or code editor. For this example, we'll use TypeScript and create a new project using the following command:npm init -y
tsc --init
#### Step 2: Install Required Packages
Install the required packages using npm or yarn:
npm install --save node-keyboard
#### Step 3: Create the Productivity Hack Script
Create a new file called `productivityHack.ts` and add the following code:
import keyboard from 'node-keyboard';
const keyboardListener = keyboard.listen({
on: 'keydown',
});
keyboardListener.on('keydown', (event) => {
if (event.keys[0] === 'Shift' && event.keys[1] === 'Esc') {
console.log('Focused mode activated!');
// Switch to focused mode
} else if (event.keys[0] === 'S') {
console.log('Distraction mode activated!');
// Switch to distraction mode
}
});
This script listens for keyboard events and switches between the two modes when the user presses the specified key combinations.
Integrating the Productivity Hack with DiggaByte
If you're using DiggaByte's Next.js + Prisma stack, you can integrate this productivity hack with your existing project by creating a new API endpoint that listens for keyboard events and switches between the two modes. #### Step 1: Create a New API Endpoint Create a new API endpoint using Next.js API routes:import { NextApiRequest, NextApiResponse } from 'next';
import keyboard from 'node-keyboard';
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
const keyboardListener = keyboard.listen({
on: 'keydown',
});
keyboardListener.on('keydown', (event) => {
if (event.keys[0] === 'Shift' && event.keys[1] === 'Esc') {
console.log('Focused mode activated!');
// Switch to focused mode
} else if (event.keys[0] === 'S') {
console.log('Distraction mode activated!');
// Switch to distraction mode
}
});
res.status(200).json({ message: 'Productivity hack activated!' });
}
#### Step 2: Integrate with Prisma
To integrate this productivity hack with Prisma, you can use the `prisma` client to update the user's status in the database:
import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
keyboardListener.on('keydown', (event) => {
if (event.keys[0] === 'Shift' && event.keys[1] === 'Esc') {
console.log('Focused mode activated!');
// Update user status to focused
prisma.user.update({
where: { id: 1 },
data: { status: 'focused' },
});
} else if (event.keys[0] === 'S') {
console.log('Distraction mode activated!');
// Update user status to distracted
prisma.user.update({
where: { id: 1 },
data: { status: 'distracted' },
});
}
});